Chrome套接字未连接服务器

时间:2014-06-13 21:26:02

标签: javascript sockets google-chrome networking google-chrome-app

我一直在尝试创建一个可以使用tcp套接字下载文件的打包Chrome应用,为了测试这个我尝试连接到我的网络服务器和我编写的快速python脚本但是似乎都不起作用。调试应用程序并查看Git Hub上提供的示例并没有帮助,所以我希望有人可以指出错误。

chrome.sockets.tcp.create(
  {persistent: false, name: 'my_socket'},
  function(createInfo) {
    var socketId = createInfo.socketId;
    var result = 0;
    chrome.sockets.tcp.connect(
      socketId, "127.0.0.1", 1234,
      function(result){
        if (result < 0){
          // There was an error.
          document.getElementById("demo").innerHTML = "There was an error with connecting";
        } else {
          chrome.sockets.tcp.send(
            socketId, "Hello World!",
            function(sendInfo){
              if (!sendInfo || sendInfo.resultCode < 0){
                // There was an error.
                document.getElementById("demo").innerHTML = "There was an error with sending the data";
              } else {
                // Data Sent, await response in chrome.sockets.tcp.onReceive
                document.getElementById("demo").innerHTML = "Everything went fine :D";
              }
          });        
        }
    });
});

0 个答案:

没有答案