美文网首页
iOS开发——socket服务器的搭建(python chats

iOS开发——socket服务器的搭建(python chats

作者: 大虾咪 | 来源:发表于2016-09-27 17:07 被阅读260次

socket服务器可通过python来搭建

在终端输入命名:

python chatserver.py

1

看到提示:Iphone Chat server started表示创建成功.

但是有的时候看到的提示是:

No module named twisted.internet.protocol:表示本机上没有安装twisted,需要自己安装.

chatserver.py下载地址.

ope.interface/twisted官网下载地址:

https://pypi.python.org/pypi/zope.interface

https://twistedmatrix.com/trac/wiki/Downloads

ope.interface/twisted 百度网盘下载地址:

链接:http://pan.baidu.com/s/1qYtcu6K密码: rr13

步骤如下:

1.苹果电脑一般都安装了python,在终端,输“which python”或“which python3”,会显示python的安装目录。

2.先安装zope.interface,才能安装twisted.

安装方法:下载gz压缩包,解压后,会看到有个”setup.py” 文件,cd 进去在终端下,输入“pythonsetup.pyinstall”或“python3setup.pyinstall”.便可以安装zope.interface。

如果出现

error: can'tcreateorremove filesininstall directory The following error occurredwhiletryingtoaddorremove filesinthe installation directory: [Errno13] Permission denied: '/Library/Python/2.7/site-packages/ test-easy-install-411.write-test' The installation directory you specified (via--install-dir, --prefix,orthe distutilsdefaultsetting) was:    /Library/Python/2.7/site-packages/ **Perhaps your account doesnothave writeaccesstothis directory?**Ifthe installation directoryisa system-owned directory, you may needtosigninas the administratoror"root"account.Ifyou donothave administrativeaccesstothis machine, you may wishtochoose a different installation directory, preferably one thatislistedinyour PYTHONPATH environmentvariable.Forinformationonother options, you may wishtoconsult the documentation at:http://peak.telecommunity.com/EasyInstall.htmlPlease make the appropriate changesforyour systemandtry again.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

这一段错误,因为python路径是在系统路径下,默认不能写.(报错的原因就是因为权限不够)

解决方案:使用命令

sudopythonsetup.pyinstall

3.检查下MAC有没有自带twisted。

检查方法:打开python命令行,输入“import twisted”,如果没有任何提示,说明你已经有twisted了,若提示没有”twisted”模块,则需要自己安装twisted。

安装方法:参考zope.interface的安装,(如果权限不够,同样在命令之前加上sudo),安装完成之后再用”import twisted”测试一下

出现下图表示通过

之后就可以用命令,开启服务了cd 进去

python chatserver.py

1

一个小demo的实例程序:

方法2

iOS开发——socket服务器的搭建

字数371阅读1470评论8喜欢10

socket服务器可通过python来搭建

源程序分享在百度云,下载链接如下:

链接:http://pan.baidu.com/s/1o6Gk0u2密码: fvju

在终端下,输入:

pythonchatserver.py

便可以成功搭建socket服务器。(ps:该源码只能在python2运行环境成功执行,python3虽然能连接但是无法发送数据。)

在iPhone测试连接socket服务器,源码如下:

链接:http://pan.baidu.com/s/1gdAsYTd密码: 684g

遇到的问题:没有twisted模块,需要自行安装

安装twisted步骤如下:

1.MAC系统一般已经安装了python,可以打开终端,输“which python”或“which python3”,会显示python的安装目录。(ps:对应不同的python版本),如果没有安装,请自行谷歌或百度。

2.需要先安装zope.interface,才能安装twisted.

下载地址:https://pypi.python.org/pypi/zope.interface

安装方法:下载gz压缩包,解压后,会看到有个"setup.py" 文件,在终端下,输入“pythonsetup.pyinstall”或“python3setup.pyinstall”.便可以安装zope.interface。

3.检查下MAC有没有自带twisted。

检查方法:打开python命令行,输入“import twisted”,如果没有任何提示,说明你已经有twisted了,若提示没有"twisted"模块,则需要自己安装twisted。

下载地址:https://twistedmatrix.com/trac/wiki/Downloads

安装方法:参考zope.interface的安装,安装完成之后再用"import twisted"测试一下

相关文章

网友评论

      本文标题:iOS开发——socket服务器的搭建(python chats

      本文链接:https://www.haomeiwen.com/subject/qnefettx.html