예제 #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);
        }
예제 #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;
                }
            }
        }
예제 #3
0
 private string Communication_SendPayload(SocketWrapper client, string request)
 {
     int sent = client.WriteString(request);
     var response = client.ReadString();
     return response;
 }
예제 #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;
            }
        }
예제 #5
0
 private void Communication_IdentifySelf(SocketWrapper socket)
 {
     socket.WriteString(string.Format(@"{0}\{1}", Environment.MachineName, Environment.UserName));
 }
예제 #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);
        }