示例#1
0
        public void StopListening()

        {
            try

            {
                RequestPending = false;

                numPackets = numProcessed = 0;



                if (pSocketClient != null)
                {
                    pSocketClient.Dispose();
                }



                pSocketClient = null;
            }

            catch (Exception pException) { LogLib.WriteLine("Error with StopListening(): " + pException.Message); }
        }
示例#2
0
        public void StopListening()

        {
            try

            {
                RequestPending = false;

                numPackets = numProcessed = 0;

                pSocketClient?.Dispose();

                pSocketClient = null;
            }
            catch (Exception pException) { LogLib.WriteLine($"Error with StopListening(): {pException.Message}"); }
        }
示例#3
0
        public bool ConnectToServer(string ServerAddress, int ServerPort, bool errMsg = true)

        {
            try {
                if (pSocketClient != null)
                {
                    Thread.Sleep(2000);

                    pSocketClient.Dispose();

                    pSocketClient = null;
                }

                // Instantiate a CSocketClient object

                pSocketClient = new CSocketClient(100000, /*, null,*/

                                                  new CSocketClient.MESSAGE_HANDLER(MessageHandlerClient),

                                                  new CSocketClient.CLOSE_HANDLER(CloseHandler)

                                                  /*new CSocketClient.ERROR_HANDLER(ErrorHandler)*/
                                                  );

                // Establish a connection to the server
                mbGetProcessInfo = true;
                pSocketClient.Connect(ServerAddress, (short)ServerPort);

                return(true);
            }
            catch (Exception pException)

            {
                string msg = $"Could not connect to the server: {pException.Message}";

                LogLib.WriteLine(msg);

                if (errMsg)
                {
                    MessageBox.Show($"{msg}\r\nTry selecting a different server!", "Server Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                return(false);
            }
        }