我正在使用套接字编程在 C# 中制作一个窗口应用程序。我开发了一个服务器和一个客户端。两者都工作正常,但我遇到的问题是,当我从客户端发送任何消息时,它会完美发送并在服务器上接收,但是每当我尝试从服务器发送任何消息时,它都不会发送给客户端,因为一开始建立连接时,服务器将“连接已建立”的消息发送给客户端并在客户端完美接收,但稍后服务器不会向客户端发送任何消息!谁能帮帮我??????问候乌梅尔
编辑:
//Code at SERVER for SENDING...
private void button_send(object sender, EventArgs e)
{
string input = textBoxWrite.Text;
byte[] SendData = new byte[1024];
ASCIIEncoding encoding = new ASCIIEncoding();
SendData = encoding.GetBytes(input);
client.Send(SendData,SendData.Length,SocketFlags.None);
textBoxShow.Text = "Server: " + input;
}
//Code at CLIENT for receiving
NetworkStream networkStream = new NetworkStream(server);
string input = textBoxUser.Text + ": " + textBoxWrite.Text;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] inputByte = encoding.GetBytes(input);
if (networkStream.CanWrite)
{
networkStream.Write(inputByte, 0, inputByte.Length);
textBoxShow.Text = textBoxShow.Text + Environment.NewLine + input;
textBoxWrite.Text = "";
networkStream.Flush();
}