首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IronPython Websockets

IronPython Websockets
EN

Stack Overflow用户
提问于 2018-07-04 15:52:58
回答 1查看 330关注 0票数 0

如何在ironpython中实现websockets?

Ironpython似乎只支持带有INET头的套接字(IPv4)。

我需要通过主机url wss:// host .websocket.org进行连接。

代码语言:javascript
复制
#socket
import socket
host = "wss://echo.websocket.org"
port = 8000

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    s.connect((host,port))
    s.send("Hello World")
finally:
    s.close()

print s

当我尝试连接时,它会给出一个:

代码语言:javascript
复制
 [Errno 11001] no addresses of the specified family associated with host

有没有更好的方法来解决这个问题?例如,导入一个专门处理websockets的外部库?

EN

回答 1

Stack Overflow用户

发布于 2018-12-17 05:39:26

我有一个类似的问题(我正在使用ObsWebsocket在python中控制obs ),我试图使用websocket,但我得到了一个类似的错误: Errno 10044在这个地址系列中不存在对指定套接字类型的支持最后,我找到了一个解决方法。我使用子进程处理所有IronPython内容,并使用Python3脚本通过套接字执行通信

我给你发一段我的代码。我希望它能有所帮助:

代码语言:javascript
复制
from subprocess import Popen, PIPE

creturn_code = Popen("ipy IronPythonScript.py", shell=True, stdout = PIPE) #You can change the ipy for py and use an similar code in IronPython
rrline = creturn_code.stdout.readline() #This read the stdout of the script

rline = str(rrline)[2: (len(rrline))] #This remove the fking b'' that is always (i dont know why)

if(rline != ""): #Check that the output of the another process realy contains something

在这里,您可以实现所需的所有功能

我在Python3上使用了它,并且它工作了。IronPython处理所有的dlls事务,而python3处理所有的通信

如果我的英语不是很好,对不起,我是阿根廷人

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51168508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档