我试图在服务器和客户端之间建立一个 tcp 连接。服务器是在 c# 上编程的,客户端是在 java 上编写的……服务器工作正常……我的问题出在这段代码中:
try {
InetAddress address = InetAddress.getByName("127.0.0.1");
connection = new Socket(address, port);
BufferedReader inFromServer = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
loginInfo = inFromServer.readLine();
System.out.println("username/pass are received");
System.out.println(loginInfo);
connection.close();
} catch (IOException f) {
System.out.println("IOException: " + f);
} catch (Exception g) {
System.out.println("Exception: " + g);
}
该应用程序被阻止,我无法再关闭它......直到我从 java 完成调试。我想问题出在 loginInfo 中,因为我没有在输出中收到用户名/密码..所以有什么帮助吗?
这是从 c# 发送消息的线程:
Thread listener_service = new Thread((ThreadStart)delegate
{
listener.Start();
while (true)
{
s = listener.AcceptSocket();
Console.WriteLine("Connected to !" + s.RemoteEndPoint);
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server. \n"));
Console.WriteLine("\nSent Acknowledgement");
continue;
}
});