예제 #1
0
        private static void Main(string[] args)
        {
            Console.WindowHeight = 20;
            Console.WindowWidth  = 80;
again:
            Console.WriteLine("---SET LOKAL IP:---");
            var ip = Console.ReadLine();

            if (ip == string.Empty)
            {
                goto again;
            }
            try
            {
                _ip = IPAddress.Parse(ip);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                goto again;
            }
            Console.WriteLine("---SET PATH TO EXAMS (leave empty for default):---");
            var exams = Console.ReadLine();

            if (exams != string.Empty)
            {
                _exampath = exams;
            }

            _server = new TCPServer(_ip, _port);
            _server.ClientConnectionChanged += OnConnectionChanged;
            _server.PacketReceived          += OnPacketReceived;
            _server.Start();
            Console.WriteLine("Server started");
            _log = new Log();
            _log.ConsoleOutput = true;

            while (true)
            {
                ;
            }
        }
        private void StopListening()
        {
            // close connections to drone and client and then close the listener down

            if (clientConnected == true)
            {
                client.Close();
            }
            if (droneConnected == true)
            {
                drone.Close();
            }
            clientConnected      = false;
            droneConnected       = false;
            txtIPAddress.Enabled = true;
            txtPort.Enabled      = true;
            button1.Text         = "Start";
            IsListening          = false;
            server.CloseServer();
            server = null;
        }
예제 #3
0
        static void Main(string[] args)
        {
            const string HOST = "localhost";
            const int    PORT = 8080;

            LoginServiceServer loginService = new LoginServiceServer();
            TCPServer          tCPServer    = new TCPServer(HOST, PORT);


            tCPServer.addHandler("CHAT", delegate(Message request)
            {
                //save message into db

                return(null);
            });

            tCPServer.addHandler("CHECK_LOGIN", delegate(Message request)
            {
                string username = request.Body.Split('?')[0];
                Console.WriteLine("username : "******"password : "******"OK";
                    response.Body   = username;
                }
                else
                {
                    response.Header = "404";
                    response.Body   = "Username or password is invalid";
                }

                return(response);
            });

            tCPServer.Start();
        }
        /// <summary>
        /// The Validation.
        /// </summary>
        /// <param name="connectionType">The connectionType<see cref="string"/>.</param>
        /// <param name="port">The port<see cref="string"/>.</param>
        /// <returns>The <see cref="IWorker"/>.</returns>
        public IWorker Validation(string connectionType, string port)
        {
            int  Port;
            bool isValidPort = Int32.TryParse(port, out Port);

            if (connectionType == "Udp")
            {
                var udpServer = new UDPServer();

                if (isValidPort)
                {
                    udpServer.Port = Port;
                }
                else
                {
                    udpServer.Port = 80;
                }

                return(udpServer);
            }
            else if (connectionType == "Tcp")
            {
                var tcpServer = new TCPServer();

                if (isValidPort)
                {
                    tcpServer.Port = Port;
                }
                else
                {
                    tcpServer.Port = 80;
                }

                return(tcpServer);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        private static void StartTCPServer(string ipAddress, int port)
        {
            TCPServer tcpServer = new TCPServer(new ConsoleMessageProcessor(), ipAddress, port);

            tcpServer.Listen();
        }
예제 #6
0
        public TCPServer server; // объект сервера

        public Client(TcpClient tcpClient, TCPServer serverObject)
        {
            Id     = Guid.NewGuid().ToString();
            client = tcpClient;
            server = serverObject;
        }
예제 #7
0
        static void Main(string[] args)
        {
            TCPServer tCP = new TCPServer();

            tCP.Start();
        }
예제 #8
0
 public FormServer()
 {
     InitializeComponent();
     server = new TCPServer(17777);
 }
예제 #9
0
 private static void InitServer()
 {
     TCPServer.Init();
 }