Alrigh, I'll just help you into a direction. The rest is for you to find out.
To make communication possible, we have to setup a server. This receives the connections from every client. It does that by listening.
Since listening requires constant attention, it will freeze up the program, unless you place it on another thread.
This is the 'Connect' class from a chat-program I've written some years back.
private string host = "127.0.0.1";
private int port = 10445;
private TcpClient client;
private NetworkStream stream;
private Byte[] data;
public int Port
{
get
{
return port;
}
set
{
port = value;
}
}
public Connect()
{
client = new TcpClient(host, port);
stream = client.GetStream();
}
public void Send(string msg)
{
data = System.Text.Encoding.ASCII.GetBytes(msg);
stream.Write(data, 0, data.Length);
}
public string Listen()
{
Byte[] data2 = new Byte[256];
String responseData = String.Empty;
Int32 bytes = 0;
try
{
bytes = stream.Read(data2, 0, data2.Length);
responseData = System.Text.Encoding.ASCII.GetString(data2, 0, bytes);
return responseData;
}
catch (IOException)
{
MessageBox.Show("Lost connection to the sever...\n\nClick ok to exit");
Application.Exit();
return null;
}
}