public bool ConnectToServer(string ServerAddress, int ServerPort, bool errMsg = true) { try { pSocketClient?.Disconnect(); // Instantiate a CSocketClient object pSocketClient = new CSocketClient(100000, new CSocketClient.MESSAGE_HANDLER(MessageHandlerClient), new CSocketClient.CLOSE_HANDLER(CloseHandler) ); // Establish a connection to the server mbGetProcessInfo = true; pSocketClient.Connect(ServerAddress, ServerPort); return(true); } catch (Exception pException) { var msg = $"{ServConErr} {pException.Message}"; LogLib.WriteLine(msg); if (errMsg) { MessageBox.Show( msg + "\r\nTry selecting a different server!", caption: ServConErr, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } return(false); } }
private void CloseHandler(CSocketClient pSocket) { if (f1 == null) { StopListening(); } else { f1.StopListening(); } }
public void StopListening() { try { RequestPending = false; numPackets = numProcessed = 0; pSocketClient?.Disconnect(); pSocketClient = null; } catch (Exception pException) { LogLib.WriteLine($"Error: StopListening: {pException.Message}"); } }
//******************************************************************** private void MessageHandlerClient(CSocketClient pSocket, int iNumberOfBytes) { ProcessPacket(pSocket.GetRawBuffer, iNumberOfBytes); }