oo-70-245-1

oo-70-245-1 Commit Details


Date:2018-10-18 22:30:15 (6 years 5 months ago)
Author:Natalie Adams
Branch:master
Commit:7a54e90e5b07055639e9b0b77ad13a44898e80d8
Parents: 9133efac475f71a7cd7960929cbfbd9d4f914ee3
Message:adding comments

Changes:

File differences

TCP/Example1/server.cs
3131
3232
3333
34
34
3535
36
36
3737
3838
3939
......
4444
4545
4646
47
47
4848
4949
50
50
5151
5252
5353
        public Server(IPAddress ip, int port = 5000)
        {
            server = new TcpListener(ip, port);
            server.Start();
            server.Start(); // Start listening on given IP and port
            Console.WriteLine("Listening on {0} on port {1}", ip.ToString(), port);
            s = server.AcceptSocket();
            s = server.AcceptSocket(); // Accept the connection as a socket into s
        }
        public Server(int port = 5000) : this(IPAddress.Loopback, port) { }
            byte[] buffer = new byte[1024];
            byte[] pong = "pong".ToByteArray();
           
            int k = s.Receive(buffer);
            int k = s.Receive(buffer); // receive data from client
            Console.WriteLine("Client sent - {0} - {1}", buffer.GetString(k), count);
            Thread.Sleep(2000);
            s.Send(pong);
            s.Send(pong); // send data to client
            Console.WriteLine("Sent to client - {0} - {1}", pong.GetString(pong.Length), count);
            count++;
            return true;
TCP/Example2/server.cs
3737
3838
3939
40
41
42
4043
4144
4245
            while (true)
            {
                s = server.AcceptSocket();
// spin up a new thread that handles
// incoming data from that client
// then loop to accept another connection
                Thread t = new Thread(Respond);
                t.Start(s);
            }
TCP/Example3/server.cs
2626
2727
2828
29
30
31
2932
3033
3134
......
3942
4043
4144
45
4246
4347
4448
                {
                    Thread t = new Thread(handleConnection);
                    Socket client = server.AcceptSocket();
// Send the socket to the thread
// let the thread deal with incoming messages
// loop and accept the next connection and repeat
                    t.Start(client);
                }
        }
        static void handleConnection(object socket)
        {
// unbox/cast socket object type to a Socket type
            Socket client = (Socket)socket;
            Console.WriteLine("Connection accepted from {0}", client.RemoteEndPoint);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.10154s using 14 queries.