使用GapSocket将字符串发送到tcp套接字 [英] Send string to a tcp socket using GapSocket

查看:139
本文介绍了使用GapSocket将字符串发送到tcp套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 GapSocket 建立套接字连接并且将一些数据(字符串)从PhoneGap发送到端口8888打开的计算机的tcp套接字。我包含了所有的依赖关系:

I am trying to establish a socket connection using GapSocket and send some data (strings) to a tcp socket from an PhoneGap to a computer with port 8888 open. I have included all dependencies:


  1. cocoaasyncsocket

  2. GapSocketCommand.m和GapSocketCommand.h都来自GapSocket

  3. 包含GapSocket.js并在www文件夹下的index.html中引用了js文件。

以下是我的index.html文件:

Following is my index.html file:

<!DOCTYPE html>
<html>
<head>
    <title>Socket Test</title>
    <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
    <script type="text/javascript">
        document.addEventListener("deviceready", function(){
            var mySocket = new GapSocket(127.0.0.1, 8888);
            mySocket.onopen = function(){ alert("Socket opened."); };
            mySocket.send("some data here");
        }, false);
     </script>
    </head>
<body>
</body>

t抛出任何依赖性错误,并能够在iOS模拟器上运行。在我运行之前,我打开端口8888在127.0.0.1(模拟器运行的机器)使用:

It compiles okay and doesn't throw any dependency error and able to run on iOS Simulator. Before I run, I opened port 8888 on 127.0.0.1 (the machine that the Simulator runs) using:


nc -l 127.0.0.1 8888

nc -l 127.0.0.1 8888

我可以使用telnet连接开放端口和发送数据:

I can connect the open port and send data by using telnet:

telnet 127.0.0.1 8888

telnet 127.0.0.1 8888

发送以下数据:

eddy-2:~ eddy$ telnet 127.0.0.1 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
test
test

回到iOS模拟器,发送任何东西,我不知道我是否正确的方式初始化套接字(我是新的PhoneGap和Xcode)。我按照自述的步骤,但它不提供太多的上下文。

Coming back to the iOS Simulator, it runs but doesn't send anything out and I am not sure if I am doing the correct way of initializing the socket (I am new to both PhoneGap and Xcode). I followed steps on the readme but it doesn't provide much context.

推荐答案

您需要在cordova.plist插件与GapSocketCommand字符串和值

you need to include an entry in cordova.plist plugin with GapSocketCommand string and value

这篇关于使用GapSocket将字符串发送到tcp套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆