I have trouble in sending an object through socket in c#, my client can send to server but server can't send to client, i think there is something wrong with the client.
Server
private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
Thread a = new Thread(connect);
a.Start();
}
private void sendButton_Click(object sender, EventArgs e)
{
client.Send(SerializeData(ShapeList[ShapeList.Count - 1]));
}
void connect()
{
try
{
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5555);
server.Bind(iep);
server.Listen(10);
client = server.Accept();
while (true)
{
byte[] data = new byte[1024];
client.Receive(data);
PaintObject a = (PaintObject)DeserializeData(data);
ShapeList.Add(a);
Invalidate();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
client
private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
Thread a = new Thread(connect);
a.Start();
}
private void SendButton_Click(object sender, EventArgs e)
{
client.Send(SerializeData(ShapeList[ShapeList.Count - 1]));
}
void connect()
{
try
{
client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5555);
client.Connect(iep);
while (true)
{
byte[] data = new byte[1024];
client.Receive(data);
PaintObject a = (PaintObject)DeserializeData(data);
ShapeList.Add(a);
Invalidate();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}