node.js写的socket服务端
var server = net.createServer();
server.listen(9999, '10.14.11.56');
server.on('connection', function(socket) {
//socket.setNoDelay(true);
console.log('CONNECTED: ' + socket.remoteAddress +':'+ socket.remotePort);
//要求客户端进行身份验证
var msg_login = {
success : true,
order : 'login'
};
socket.write(JSON.stringify(msg_login));
});
java完成的socket客户端,但是需要3~5分钟才能接收到消息!
这是怎么回事?用node.js写的socket客户端就秒接收
3 回复
@leapon try { Socket socket=new Socket(IP,Port); BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream())); String readline; readline=is.readLine(); //从系统标准输入读入一字符串
System.out.print(readline);
} catch (UnknownHostException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
就这个简单的java代码,卡在readline那!