尝试连接socket与phonegap

时间:2016-04-13 15:21:40

标签: javascript android python json

我正在尝试连接Virtualbox的套接字,虚拟机中的服务器部分和phonegap,并且无法正常工作,我做错了什么?连接必须是TCP,其中客户是我的Android应用程序,而我的服务器是计算机。但它总是会产生同样的错误。

我的错误:

  

XMLHttpRequest无法加载https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_ ... 168.1.111%3A10000 / socket.io /%3FEIO%3D3%26transport%3Dpolling%26t%3DLGGA1OE。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许原点“http://192.168.56.1:3000”访问。响应的HTTP状态代码为503。

我在Android中的控制器是:

angular.module ( 'starter.controllers' [])

.controller ( 'DashCtrl', function ($ scope) {
    console.log ( "tesssssssssssssssssssssssss");
    var socket = io.connect ( '192.168.1.111:10000');
    socket.emit ( "test", { "lat": 41, "long": -8});

})

我的服务器是:

def get_pressure_and_temperature (request_string):
    JSON_OBJECT = json.loads (request_string)
    print JSON_OBJECT
    timestamp = timestamp # aux.get_date ()
    hour = hour aux.get_time # ()
    latitude = float (JSON_OBJECT [ "lat"])
    longitude = float (JSON_OBJECT [ "long"])
    pressure_temperature_result = pressure_temperature.build_data (timestamp, hour, latitude, longitude)
    jresult = json.dumps (pressure_temperature_result)
    return jresult

HOST = '# Symbolic name meaning all available interfaces
PORT = 10000 # Arbitrary non-privileged port
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.bind ((HOST, PORT))
s.listen (1)

while True:
conn, customer s.accept = ()
pid = os.fork ()
if pid == 0:
s.close ()
print 'Connected by' customer
#while True:
                request_string = conn.recv (1024)
                print "received," request_string
                # Conn.send (get_pressure_and_temperature (request_string))
if not request_string: break
print "Finalizing connection with customer," customer
# Conn.close ()
sys.exit (0)
else:
conn.close ()

1 个答案:

答案 0 :(得分:0)

我认为这是你的问题:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

我认为您需要首先为您的应用设置一些权限。

也许还有来自服务器的回复。

我自己在科尔多瓦工作,所以我不确定这些日子在Phonegap中是怎么回事。

以下是两个可能有用的链接

No 'Access-Control-Allow-Origin' header is present on the requested resource- AngularJS

no-access-control-allow-origin-header-is-present-on-the-requested-resource