我試圖在服務器和客戶端之間建立一個tcp連接。服務器在C#和Java的編程cliend ...服務器工作正常...我的問題是這樣的代碼:我的應用程序(服務器/客戶端)在使用Readline後被阻止
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;
}
});
你的C#代碼在最後發送一個帶有回車/換行符的字符串嗎? –
爲什麼不在''while'循環中編寫'inFromServer.readLine()'?你如何知道是否沒有更多的數據要從服務器讀取? –
ive只是添加了從c#發送消息從服務器的線程..我一直在這個問題上工作30小時,我還沒有解決..我搜查了所有的互聯網,並沒有得到答案..所以我appriciate任何幫助..即時新的網絡連接 – jolyTimePopCorn