public void StartForTestOnly(int port, System.Threading.CancellationToken token) { _udpThread = new System.Threading.Thread(() => _udpReceiver.ReceiveStuff(token)); _udpThread.Start(); System.Net.Sockets.TcpListener serverSocket = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, port); SocketEventInfo?.Invoke("Listening"); System.Net.Sockets.TcpClient clientSocket = default(System.Net.Sockets.TcpClient); int clientId = 0; serverSocket.Start(); clientId = 0; while (!token.IsCancellationRequested) { clientId += 1; clientSocket = serverSocket.AcceptTcpClient(); _log.Debug($"New TCP Client connected"); System.Threading.Thread thread = new System.Threading.Thread(() => StartServerMessengerForTest(clientSocket, clientId, token)); thread.Start(); } clientSocket.Close(); serverSocket.Stop(); SocketEventInfo?.Invoke("Closed"); }
public bool Connect(string ipAddress, int port) { try { _clientSocket.Connect(ipAddress, port); SocketEventInfo?.Invoke("Connected"); testConnect = true; System.Threading.Thread thread = new System.Threading.Thread(() => GetStream(_cancelToken)); thread.Start(); //var publicKey = encryptioinKeys.ExportPublicKey(); //System.Threading.Thread.Sleep(100); //_log.Debug("Sending RSA Public Key"); //CallReceivedDataLog("Sending RSA Public Key"); //SendObjectToTcpClient(new TanksCommon.Encryption.RsaPublicKey() { Key = publicKey }); return(true); } catch { SocketEventInfo?.Invoke("Failed"); testConnect = false; return(false); } }
private void _serverComManager_SocketEventInfo(string socketEvent) { SocketEventInfo?.Invoke(socketEvent); }
private void _mainServerMessenger_SocketEventInfo(string socketEvent) { SocketEventInfo?.Invoke(socketEvent); }