소켓 프로그래밍을 사용하여 C#에서 Window 응용 프로그램을 만드는 중입니다. 나는 서버 & 클라이언트를 개발했다. 둘 다 잘 작동하지만 문제는 내가 점점 클라이언트에서 메시지를 보낼 때 완벽하게 보내고 서버에서받습니다하지만 내가 서버에서 메시지를 보내려고 할 때마다 그것은 클라이언트에게 보내지 않습니다. 처음부터 연결이 구축되면 서버는 "Connection Established"라는 메시지를 클라이언트에 전송하고 클라이언트에서 완벽하게 수신하지만 나중에 서버는 클라이언트에 메시지를 보내지 않습니다 !!! 아무도 나를 도와 줄 수 없었어요 ??????? 감사 UMAIR서버에서 클라이언트로 메시지를 보낼 때 문제가 발생했습니다.
편집 :
//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();
}
몇 가지 샘플 코드를 게시 할 수 있습니까? –
제공 한 샘플 코드에서 "수신 할 CLIENT의 코드"가 전혀 수신되지 않습니다. 실제로 NetworkStream에 데이터를 쓰고 있으며 NetworkStream에서 데이터를 읽지 않습니다. 보다 정확한 코드 예제를 제공 할 수 있습니까? –