Monday, December 21, 2009

Simple Socket Client to connect to a server

private void ConnectToServer()
using (TcpClient tc = new TcpClient("", 12))
NetworkStream ns = tc.GetStream();
StreamWriter sw = new StreamWriter(ns);
StreamReader sr = new StreamReader(ns);

sw.WriteLine("test message");
This code can be used to connect to a server using a socket and send a simple message to it.

No comments: