Add `--socket_udp` CLI flag
This commit is contained in:
parent
23b571eac9
commit
20e5c43bc8
|
@ -16,9 +16,11 @@ namespace BizHawk.Client.Common
|
|||
=> Encoding.ASCII.GetBytes(payload.Length.ToString()).Concat(LENGTH_PREFIX_SEPARATOR).ToArray()
|
||||
.ConcatArray(payload);
|
||||
|
||||
private readonly ProtocolType _protocol;
|
||||
|
||||
private IPEndPoint _remoteEp;
|
||||
|
||||
private Socket _soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
private Socket _soc;
|
||||
|
||||
private readonly Func<byte[]> _takeScreenshotCallback;
|
||||
|
||||
|
@ -64,16 +66,21 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public bool Successful { get; private set; }
|
||||
|
||||
public SocketServer(Func<byte[]> takeScreenshotCallback, string ip, int port)
|
||||
public SocketServer(Func<byte[]> takeScreenshotCallback, ProtocolType protocol, string ip, int port)
|
||||
{
|
||||
_protocol = protocol;
|
||||
ReinitSocket(out _soc);
|
||||
_takeScreenshotCallback = takeScreenshotCallback;
|
||||
TargetAddress = (ip, port);
|
||||
}
|
||||
|
||||
private void ReinitSocket(out Socket socket)
|
||||
=> socket = new(AddressFamily.InterNetwork, SocketType.Stream, _protocol);
|
||||
|
||||
private void Connect()
|
||||
{
|
||||
_remoteEp = new IPEndPoint(IPAddress.Parse(_targetAddr.HostIP), _targetAddr.Port);
|
||||
_soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
ReinitSocket(out _soc);
|
||||
_soc.Connect(_remoteEp);
|
||||
Connected = true;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
|
||||
using BizHawk.Common.CollectionExtensions;
|
||||
|
||||
|
@ -42,6 +43,7 @@ namespace BizHawk.Client.Common
|
|||
string? urlPost = null;
|
||||
bool? audiosync = null;
|
||||
string? openExtToolDll = null;
|
||||
var socketProtocol = ProtocolType.Tcp;
|
||||
List<(string Key, string Value)>? userdataUnparsedPairs = null;
|
||||
string? cmdRom = null;
|
||||
|
||||
|
@ -135,6 +137,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
socketIP = argDowncased.Substring(argDowncased.IndexOf('=') + 1);
|
||||
}
|
||||
else if (argDowncased.StartsWith("--socket_udp"))
|
||||
{
|
||||
socketProtocol = ProtocolType.Udp;
|
||||
}
|
||||
else if (argDowncased.StartsWith("--mmf="))
|
||||
{
|
||||
mmfFilename = arg.Substring(arg.IndexOf('=') + 1);
|
||||
|
@ -211,6 +217,7 @@ namespace BizHawk.Client.Common
|
|||
httpAddresses: httpAddresses,
|
||||
audiosync: audiosync,
|
||||
openExtToolDll: openExtToolDll,
|
||||
socketProtocol: socketProtocol,
|
||||
userdataUnparsedPairs: userdataUnparsedPairs,
|
||||
cmdRom: cmdRom
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -36,6 +37,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public readonly (string IP, int Port)? SocketAddress;
|
||||
|
||||
public readonly ProtocolType SocketProtocol;
|
||||
|
||||
public readonly IReadOnlyList<(string Key, string Value)>? UserdataUnparsedPairs;
|
||||
|
||||
public readonly string? MMFFilename;
|
||||
|
@ -68,6 +71,7 @@ namespace BizHawk.Client.Common
|
|||
(string? UrlGet, string? UrlPost)? httpAddresses,
|
||||
bool? audiosync,
|
||||
string? openExtToolDll,
|
||||
ProtocolType socketProtocol,
|
||||
IReadOnlyList<(string Key, string Value)>? userdataUnparsedPairs,
|
||||
string? cmdRom)
|
||||
{
|
||||
|
@ -90,6 +94,7 @@ namespace BizHawk.Client.Common
|
|||
HTTPAddresses = httpAddresses;
|
||||
this.audiosync = audiosync;
|
||||
this.openExtToolDll = openExtToolDll;
|
||||
SocketProtocol = socketProtocol;
|
||||
UserdataUnparsedPairs = userdataUnparsedPairs;
|
||||
this.cmdRom = cmdRom;
|
||||
}
|
||||
|
|
|
@ -466,7 +466,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
: null,
|
||||
new MemoryMappedFiles(NetworkingTakeScreenshot, _argParser.MMFFilename),
|
||||
_argParser.SocketAddress is var (socketIP, socketPort)
|
||||
? new SocketServer(NetworkingTakeScreenshot, socketIP, socketPort)
|
||||
? new SocketServer(NetworkingTakeScreenshot, _argParser.SocketProtocol, socketIP, socketPort)
|
||||
: null
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue