string clientOrServer; Stream _stream; string read; Stream getTcpStream() { TcpClient client; IPEndPoint meetingPoint = new IPEndPoint(IPAddress.Parse("79.178.57.135"), 8080); if(clientOrServer.ToLower().StartsWith("c")) { client = new TcpClient(); client.Connect(meetingPoint); } else { TcpListener listener = new TcpListener(meetingPoint.Port); listener.Start(); client=listener.AcceptTcpClient(); listener.Stop(); } return client.GetStream(); } void clientServerclick(System.Windows.Forms.PictureBox picturebox) { StreamWriter writer = new StreamWriter(_stream); writer.AutoFlush = true; if (picturebox == pictureBox89) { writer.WriteLine("{0}", pictureBox89); } if (picturebox == pictureBox51) { writer.WriteLine("{0}", pictureBox51); } } void readclick() { StreamReader reader = new StreamReader(_stream); string a = reader.ReadLine(); Console.WriteLine(a); }this is the code for client generating connection clientOrServer = "c"; _stream = getTcpStream(); Console.WriteLine("Connected");server clientOrServer = "s"; _stream = getTcpStream(); Console.WriteLine("Connected");this runs when a click on a soldier occurs clientServerclick(pictureBox);