1
我正在用C#客戶套接字和Java服務器套接字創建一個套接字連接。 當我從客戶端套接字發送數據時,服務器套接字正在正確接收該數據。 但是當我試圖從服務器套接字發送數據回到客戶端套接字時,它在客戶端接收數據時被掛起。從Java服務器套接字接收C#客戶端套接字中的數據時出錯
客戶端代碼(在C#.NET)
clientSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
string hostName = System.Net.Dns.GetHostName();
System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(hostName);
System.Net.IPAddress[] ipAddresses = hostEntry.AddressList;
System.Net.IPEndPoint remoteEP =
new System.Net.IPEndPoint(ipAddresses[ipAddresses.Length - 1], port);
clientSocket.Connect(remoteEP);
string sendData = inputFilePath;
byte[] byteDataSend = System.Text.Encoding.ASCII.GetBytes(sendData);
clientSocket.Send(byteDataSend);
int receivedBufferSize = clientSocket.ReceiveBufferSize;
byte[] recivedData = new Byte[receivedBufferSize];
int receivedDataLength = clientSocket.Receive(recivedData);
string stringData = Encoding.ASCII.GetString(recivedData, 0, receivedDataLength);
textFilePath = stringData;
Console.Write(stringData);
clientSocket.Close();
服務器套接字代碼(在Java)
Socket connection = server.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
fileName = in.readLine();
convertedFile =runConverter.convertDocumet(fileName);
byte[] sendingData = convertedFile.getBytes("US-ASCII");
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
dos.write(sendingData, 0, sendingData.length);
告訴我是什麼問題? 請幫忙...