Пример #1
0
        //static int x;
        //private static BackgroundWorker mainBackgroundWorker;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]
        static void Main()
        {
            //Console.WriteLine("EchoSync");
            //Console.Out.WriteLine("EchoSync Out");
            Logger.Init("C:\\Temp\\application.log");
            Logger.Log("first log message");
            //smallFunc();

            /*Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * Form1 f = new Form1();
             * Application.Run(f);
             * Console.Out.WriteLine("line");
             * f.textBox1.Text = "test string 1";*/

            EchoSyncSocket serverSocket = new EchoSyncSocket();

            serverSocket.InitClient(Network.SERVER_HOST, Network.SERVER_PORT);
            while (true)
            {
                String line = Console.ReadLine();
                if (line == "")
                {
                    break;
                }
                byte[] msg = System.Text.Encoding.UTF8.GetBytes(line);
                Console.Write(msg);
                serverSocket.Write(msg, 0, msg.Length);
            }
        }
Пример #2
0
 public Server()
 {
     clientSockets = new List <EchoSyncSocket>();
     try
     {
         serverSocket = new EchoSyncSocket();
         serverSocket.InitServer();
         AcceptClient();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey(false);
 }
Пример #3
0
        private void AcceptedClient(TcpClient client)
        {
            Console.WriteLine("Server.AcceptClient\t" + client.Client.RemoteEndPoint);
            EchoSyncSocket ess = serverSocket.EchoSyncSocketFromTcpClient(client);

            Console.WriteLine("AcceptedClient");
            if (ess == null)
            {
                Console.WriteLine("failed to auth as server");
                return;
            }
            Console.WriteLine("Authed as server to client: " + ess.RemoteEndPoint);
            while (true)
            {
                byte[] buffer = new byte[1024];
                int    count  = ess.Read(buffer, 0, 1024);
                String msg    = System.Text.Encoding.UTF8.GetString(buffer, 0, count);
                Console.WriteLine("received from client: " + msg);
            }
        }