windows forms tcp connection problem

csharp , tcp p2p csharp Haifa, Israel
  • 12 years ago
    Hi, I built a checkers game in C# in which players sitting next to each other can play. I am now trying to upgrade it, to become internet based. I want to generate a simple P2P connection. I wrote this code to see if a connection is established but for some reason it freezes when pressing the connection button. Please help me sort this out. Or if you think this code is unsuitable, than please help me out with this.. here is the code string clientOrServer; Stream _stream; string read; Stream getTcpStream() { TcpClient client; IPEndPoint meetingPoint = new IPEndPoint(IPAddress.Parse(""), 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 == pictureBox) { 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); If this code is off, please guide me on how to accomplish this sort of thing.THANKS

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens