Server:
Using system. net; using system. net. sockets; using system. collections. generic; using system. LINQ; using system. text; namespace serverconsole {class server {static void main (string [] ARGs) {console. writeline ("server is runing... "); IPaddress IP = new IPaddress (New byte [] {127,0, 8500}); tcplistener listener = new tcplistener (IP,); listener. start (); // start listening while (true) {// gets a connection, the method of interruption tcpcl Ient remoteclient = listener. accepttcpclient (); // print the client connection information console. writeline ("Client Connected! {0} ----> {1} ", remoteclient. Client. localendpoint, remoteclient. Client. remoteendpoint );}}}}
Client:
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. net; using system. net. sockets; namespace clientconsole {class client {static void main (string [] ARGs) {console. writeline ("client is running... "); tcpclient client = NULL; For (INT I = 0; I <3; I ++) {client = new tcpclient (); try {// establish a connection with the server client. connect ("localhost", 8500);} catch (exception ex ){ Console. writeline ("exception occured .." + ex. Message); return;} // The output is already connected to console. writeline ("server connected! {0} --> {1} ", client. client. localendpoint, client. client. remoteendpoint);} consolekey key; do {key = console. readkey (true ). key;} while (key! = Consolekey. q );}}}