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);
告诉我是什么问题? 请帮忙...