Java / JSP发送TCP数据包并等待响应

时间:2015-08-21 14:58:27

标签: java jsp sockets networking tcp

我正在尝试发送TCP数据包。它正确地发送到服务器但发送者没有得到响应(服务器正在发送响应正确)。客户端甚至不处理发送数据包的代码......

 Socket socket = new Socket (ip, port);

 PrintWriter mOut = new PrintWriter(socket.getOutputStream(), true);  
 mOut.print("DSPSYSSTS");

 //Everything works fine until here

 BufferedReader mIn = new BufferedReader (new InputStreamReader (socket.getInputStream ()));
 String fromClient = mIn.readLine();
 out.println ("Client Message: " + fromClient);

 mOut.close();
 mIn.close ();      
 socket.close ();

JSP不会打印输入,它会一直保持加载状态。怎么了?

在以下代码中返回systemRequest.request的字符串

ReadSpoolFile readSplf = new ReadSpoolFile(splfArray.get(0));
String splfContent = readSplf.read();

GetSystemStatus getSysSts = new GetSystemStatus();
String systemStatus = getSysSts.get(splfContent);
return systemStatus + "\r\n";

服务器端响应:

String response = systemRequests.request(message, SystemRequests.SILENT_OFF);

ChannelBuffer mCbResponse;

if(response != null){
mCbResponse = ChannelBuffers.copiedBuffer(response.getBytes());
mChannel.write(mCbResponse);    //<------Write response

1 个答案:

答案 0 :(得分:2)

试试这个:

mOut.print("DSPSYSSTS");
mOut.flush();
...