[英]iOS - How to connect to flask server using flask-socketIO with out namespace?
I'm building an iOS app which receive data from socket. 我正在构建一个从套接字接收数据的iOS应用。 I'm quite new to things about socket.
我对套接字的了解很新。
I use flask framework to build my server. 我使用flask框架构建服务器。 To implement the long poll, I find the
flask-socketIO
package. 为了实现长时间轮询,我找到了
flask-socketIO
软件包。 However I haven't found some useful tutorial. 但是我还没有找到一些有用的教程。
I use CocoaAsyncSocket to conncet and send data to the server and it works fine when I test a naive python socket. 我使用CocoaAsyncSocket连接并发送数据到服务器,并且在测试朴素的python套接字时工作正常。 Code:
码:
from socket import *
from time import ctime
serverClient = socket(AF_INET, SOCK_STREAM)
HOST='127.0.0.1'
PORT=8808
BUFSIZ=1024
ADDR=(HOST, PORT)
serverClient.bind(ADDR)
serverClient.listen(5)
while True:
print('waiting for input')
clientSocket, addr = serverClient.accept()
print('connect from ', addr)
while True:
try:
data= clientSocket.recv(BUFSIZ)
except:
print(e)
clientSocket.close()
break
if not data:
break
s='Hi,you send me :[%s] %s' %(ctime(), data.decode('utf8'))
clientSocket.send(s.encode('utf8'))
print([ctime()], ':', data.decode('utf8'))
clientSocket.close()
serverClient.close()
However, I don't know how to put it together with my flask server. 但是,我不知道如何将其与Flask服务器一起使用。 This is also why I try
flask-socketIO
. 这也是为什么我尝试
flask-socketIO
。
Under the instruction of the document , I implement 在文件的指导下,我执行
@socketio.on('connect', namespace='/test')
def test_connect():
emit('my response', {'data': 'Connected'})
in my views.py
. 在我的
views.py
。
Can I do without specifying the namespace
? 是否可以不指定
namespace
? But without specifying a namespace, the default one is '/'
, will it conflict with my home directory? 但是,如果不指定名称空间,则默认名称为
'/'
,它将与我的主目录冲突吗?
Socket.IO is a specialized protocol, not a plain networking library. Socket.IO是专用协议,而不是普通的网络库。 If you are going to use Socket.IO on your server, then you need to use a Socket.IO client on your iOS device, such as this one: https://github.com/socketio/socket.io-client-swift .
如果要在服务器上使用Socket.IO,则需要在iOS设备上使用Socket.IO客户端,例如: https : //github.com/socketio/socket.io-client-swift 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.