Example #1
0
        internal void Start()
        {
            var socket = new SocketWrapper(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp));
            socket.Bind(new IPEndPoint(IPAddress.Parse(Config.Current.IpAddress), Config.Current.ListenPort));
            socket.Listen(Config.Current.MaxPendingConnections);

            var thread = new Thread(this.Communication_ListenIncoming);
            thread.Start(socket);
        }
Example #2
0
        private void Communication_Begin(SocketWrapper socket)
        {
            var stop = false;
            while (!stop)
            {
                var command = socket.ReadString();

                switch (command)
                {
                    case Connection.STOP:
                        stop = true;
                        socket.Close(false);
                        this.IsConnectionInProgress = false;
                        break;
                    case Connection.EXIT:
                        stop = true;
                        this.IsExiting = true;
                        break;
                    default:
                        this.Execute(socket, command);
                        break;
                }
            }
        }
Example #3
0
 private string Communication_SendPayload(SocketWrapper client, string request)
 {
     int sent = client.WriteString(request);
     var response = client.ReadString();
     return response;
 }
Example #4
0
        private void Communication_Open()
        {
            var socket = new SocketWrapper(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp));

            try
            {
                socket.Connect(new IPEndPoint(IPAddress.Parse(Config.Current.IpAddress), Config.Current.ListenPort));

                this.Communication_IdentifySelf(socket);
                this.Communication_Begin(socket);
            }
            catch (SocketException) // Server not running
            {
                this.IsConnectionInProgress = false;
            }
        }
Example #5
0
 private void Communication_IdentifySelf(SocketWrapper socket)
 {
     socket.WriteString(string.Format(@"{0}\{1}", Environment.MachineName, Environment.UserName));
 }
Example #6
0
        private void Execute(SocketWrapper socket, string command)
        {
            if (!this._processes.ContainsKey(socket))
            {
                this._processes.Add(socket, this.CreateProcess());
            }

            var process = this._processes[socket];
            process.StandardInput.WriteLine(command);

            socket.WaitForEof(500);
        }