// the server
Using system.io; using system.net; using system.net.sockets; using system.text;
namespace SocketTest {public class Server3 {public Server3 () {} public void run () {string data; IPEndPoint ipep = new IPEndPoint (IPAddress.Any, 9050); Socket newsock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType .Tcp); Newsock.bind (IPEP); Newsock.Listen (10); console.writeline ("Waiting for aclient ..."); socket client = news.accept (); IpendPoint NewClient = (ipendPoint) Client. RemoteEndPoint; Console.WriteLine ( "Connected with {0} at port {1}", newclient.Address, newclient.Port); NetworkStream ns = new NetworkStream (client); StreamReader sr = new StreamReader (ns); StreamWriter sw = new Streamwriter (NS); String Welcome = "Welcome to my test server"; sw.writeline (Welcome); sw.flush (); while (true) {Try {data = sr.readline ();} catch (ooException) { Break;} console.writeline (data); sw.flush ();} console.writeline ("Disconnected from {0}", newclient.address; sw.cl OSE (); sr.close (); ns.close ();}}}
/
// the client
Using system.io; using system.net; using system.net.sockets; using system.text;
Namespace Sockettest {