Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 private void CloseHandler(CSocketClient pSocket)
 {
     if (f1 == null)
     {
         StopListening();
     }
     else
     {
         f1.StopListening();
     }
 }
Exemplo n.º 3
0
 public void StopListening()
 {
     try
     {
         RequestPending = false;
         numPackets     = numProcessed = 0;
         pSocketClient?.Disconnect();
         pSocketClient = null;
     }
     catch (Exception pException) { LogLib.WriteLine($"Error: StopListening: {pException.Message}"); }
 }
Exemplo n.º 4
0
 //********************************************************************
 private void MessageHandlerClient(CSocketClient pSocket, int iNumberOfBytes)
 {
     ProcessPacket(pSocket.GetRawBuffer, iNumberOfBytes);
 }