首先这是我的服务器代码的一部分:
while (true)
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
rCount = Convert.ToString(requestCount);
serverResponse = "Server to clinet(" + clNo + ") " + " are u there ?" + Environment.NewLine;
sendBytes = Encoding.ASCII.GetBytes(serverResponse);
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Flush();
Console.WriteLine(" >> " + serverResponse);
}
catch (Exception ex)
{
Console.WriteLine(" >> error : " + ex.Message);
}
}
这是我在客户端的代码:
String k= null;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
k = br.readLine();
System.out.println(k);
}
catch (IOException f) {
System.out.println("error is : "+f.getMessage());
}
catch (Exception g) {
JOptionPane.showMessageDialog(null,"Server is offline","Alert !",JOptionPane.WARNING_MESSAGE);
}
这里的错误是我的程序正在进入一个未完成的循环并在服务器输出中一直说......“>>服务器到clinet(1)你在那里吗?”
此外,我的客户端应用程序在没有收到消息的情况下冻结..!有什么帮助吗?thx :) (顺便说一句,我的客户端在 java 上,而我的服务器在 c# 上)