我对Java Server应用程序有一个奇怪的问题。客户端连接没有问题。它发送第一条消息并且服务器回复,然后客户端没有问题地收到答案。然后,客户端发送第二条消息,服务器读取此消息并回答没有问题,但客户端没有收到也没有看到答案。
这是代码,你看错了吗?也许问题出在客户端应用程序中,但我无法访问其代码。
public static final int puerto = 5698;
private static ServerSocket serverSocket;
private static Socket clientSocket;
private static DataInputStream streamFromClient;
private static DataOutputStream streamToClient;
private static final byte[] buffer_msg = new byte[4096];
private static int length_message_received;
private static byte[] message;
public static void main(String[] args)
{
try
{
serverSocket = new ServerSocket(puerto);
}
catch (IOException ex)
{
System.exit(0);
}
while ( true )
{
try
{
clientSocket = serverSocket.accept();
streamFromClient= new DataInputStream(clientSocket.getInputStream());
streamToClient= new DataOutputStream(clientSocket.getOutputStream());
while ( true )
{
length_message_received= streamFromClient.read(buffer_msg);
if ( length_message_received< 0 )
break;
message= new byte[length_message_received];
System.arraycopy(buffer_msg, 0, message, 0, length_message_received);
//THIS METHOD CREATES THE ANSWER
byte answer[] = answerer(message);
streamToClient.write(answer);
}
streamFromClient.close();
streamToClient.close();
clientSocket.close();
}
catch (IOException ex)
{
}
}
}
抱歉我的英文。如果你不了解某些事情,请告诉我。