1. simple Server/* using system. data; using system. net. sockets; using system. net; using system. threading; Private Static int Port = % 2; Private Static thread ththreadread; Private Static tcplistener tcplisten; Private Static bool blistener = true; Private Static socket stread; */Private Static void listen () {try {tcplisten = new tcplistener (port); tcplisten. start (); stread = tcplisten. acceptsocket (); endpoint tempremoteep = stread. remoteendpoint; ipendpoint tempremoteip = (ipendpoint) tempremoteep; iphostentry host = DNS. gethostbyaddress (tempremoteip. address); string shostname = host. hostname; while (blistener) {stread. send (encoding. ASCII. getbytes (% 1); string stime = datetime. now. toshorttimestring (); byte [] byread = new byte [1024]; int Iread = stread. receivefrom (byread, ref tempremoteep); byte [] bytext = new byte [Iread]; array. copy (byread, 0, bytext, 0, Iread); string line = system. text. encoding. default. getstring (byread) ;}} catch (system. security. securityexception) {// listener Failed} ththreadread = new thread (New threadstart (Listen); ththreadread. start (); 2. simple client/* using system. data; using system. net. sockets; using system. net; Private Static ipendpoint datetimehost; */string hostipstring = % 1; string hostportstring = % 2; IPaddress hostip = IPaddress. parse (hostipstring); datetimehost = new ipendpoint (hostip, int32.parse (hostportstring); socket conn = new socket (addressfamily. interNetwork, sockettype. stream, protocoltype. TCP); Conn. connect (datetimehost); int bytes = 0; byte [] recvbytes = new byte [256]; bytes = Conn. receive (recvbytes, recvbytes. length, 0); string recvstring = encoding. ASCII. getstring (recvbytes, 0, bytes); console. writeline (recvstring); Conn. shutdown (socketshutdown. both); Conn. close (); 3. obtain the local IP address // using system. net; IPaddress [] Addresslist = DNS. gethostbyname (DNS. gethostname ()). addresslist; string % 1 = NULL; For (INT I = 0; I <Addresslist. length; I ++) {% 1 + = Addresslist [I]. tostring ();}