data send by firefox tcp socket.send() can't retrive until close the socket

不羁岁月 提交于 2019-12-01 12:54:49

It's actually working. Your data is being received, but you're currently waiting for a new line to print your received messages:

while ((inputLine = in.readLine()) != null) {
    System.out.println("Server: " + inputLine);
    out.println(inputLine);

    if (inputLine.equals("Bye.")) {
        break;
    }
}

Which currently only happens when you close the socket. Just add a new line at the end of your messages and it will work as expected:

var tcpSocket = Cc["@mozilla.org/tcp-socket;1"].createInstance(Ci.nsIDOMTCPSocket);
var socket    = tcpSocket.open("127.0.0.1", 5000);

function sendMessage(msg){
    socket.send(msg + "\n");
}

setTimeout(function(){
    sendMessage("hi mark");
},3000);

setTimeout(function(){
    sendMessage("hi johnny");
},5000); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!