Change udp port opening routine for some scenarios

Experimental
This commit is contained in:
Travis Nickles 2018-12-05 05:16:54 -06:00
parent 0f3d6e379a
commit ea3787eef2

View File

@ -177,7 +177,7 @@ namespace DS4Windows
Monitor.Pulse(busThrLck);
}
public void ChangeUDPStatus(bool state)
public void ChangeUDPStatus(bool state, bool openPort=true)
{
if (state && _udpServer == null)
{
@ -185,19 +185,25 @@ namespace DS4Windows
TestQueueBus(() =>
{
_udpServer = new UdpServer(GetPadDetailForIdx);
var UDP_SERVER_PORT = Global.getUDPServerPortNum();
try
if (openPort)
{
_udpServer.Start(UDP_SERVER_PORT);
LogDebug("UDP server listening on port " + UDP_SERVER_PORT);
}
catch (System.Net.Sockets.SocketException ex)
{
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode);
Task.Run(() =>
{
var UDP_SERVER_PORT = Global.getUDPServerPortNum();
LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true);
try
{
_udpServer.Start(UDP_SERVER_PORT);
LogDebug("UDP server listening on port " + UDP_SERVER_PORT);
}
catch (System.Net.Sockets.SocketException ex)
{
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode);
LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true);
}
}).Wait();
}
udpChangeStatus = false;
@ -312,7 +318,7 @@ namespace DS4Windows
if (isUsingUDPServer() && _udpServer == null)
{
ChangeUDPStatus(true);
ChangeUDPStatus(true, false);
while (udpChangeStatus == true)
{
Thread.SpinWait(500);
@ -426,6 +432,25 @@ namespace DS4Windows
}
running = true;
if (_udpServer != null)
{
//var UDP_SERVER_PORT = 26760;
var UDP_SERVER_PORT = Global.getUDPServerPortNum();
try
{
_udpServer.Start(UDP_SERVER_PORT);
LogDebug("UDP server listening on port " + UDP_SERVER_PORT);
}
catch (System.Net.Sockets.SocketException ex)
{
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode);
LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true);
}
}
}
else
{