내 컴퓨터 (LocalHost)에서 실행되는 서버 응용 프로그램에서 하나의 응답 만받는 이유를 파악하는 데 문제가 있습니다. 이 서버 응용 프로그램의 소스가 없지만 Java 응용 프로그램입니다. 보낸 메시지는 xml 구조이며 EoT 태그로 끝나야합니다.C# 소켓. 오직 첫 번째 메시지 만받을 수 있습니다.
통신 :
- 클라이언트가 단절 연결합니다.
- 클라이언트가 서버에 메시지를 보냅니다.
- 서버는 클라이언트에게 recived 메시지를 보냅니다.
- 클라이언트가 서버에 메시지를 보냅니다.
- 서버에서 전송 종료 문자를 보냅니다.
- 클라이언트가 서버에 메시지를 보냅니다.
- 서버에서 전송 종료 문자를 보냅니다.
이 내 클라이언트가 연결 전송 및 수신하는 방법입니다
public bool ConnectSocket(string server, int port)
{
System.Net.IPHostEntry hostEntry = null;
try
{
// Get host related information.
hostEntry = System.Net.Dns.GetHostEntry(server);
}
catch (System.Exception ex)
{
return false;
}
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not compatible with the address family
// (typical in the IPv6 case).
foreach (System.Net.IPAddress address in hostEntry.AddressList)
{
System.Net.IPEndPoint ipe = new System.Net.IPEndPoint(address, port);
System.Net.Sockets.Socket tempSocket = new System.Net.Sockets.Socket(ipe.AddressFamily, System.Net.Sockets.SocketType.Stream,
System.Net.Sockets.ProtocolType.Tcp);
tempSocket.Connect(ipe);
if (tempSocket.Connected)
{
m_pSocket = tempSocket;
m_pSocket.NoDelay = true;
return true;
}
else
continue;
}
return false;
}
}
public void Send(string message)
{
message += (char)4;//We add end of transmission character
m_pSocket.Send(m_Encoding.GetBytes(message.ToCharArray()));
}
private void Recive()
{
byte[] tByte = new byte[1024];
m_pSocket.Receive(tByte);
string recivemessage = (m_Encoding.GetString(tByte));
}