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("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);
If this code is off, please guide me on how to accomplish this sort of thing.THANKS