iOS開發(fā)——socket服務(wù)器的搭建(python chatserver.py)

socket服務(wù)器可通過python來(lái)搭建

在終端輸入命名:

python chatserver.py

1

看到提示:Iphone Chat server started表示創(chuàng)建成功.

但是有的時(shí)候看到的提示是:

No module named twisted.internet.protocol:表示本機(jī)上沒有安裝twisted,需要自己安裝.

chatserver.py下載地址.

ope.interface/twisted官網(wǎng)下載地址:

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

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

ope.interface/twisted 百度網(wǎng)盤下載地址:

鏈接:http://pan.baidu.com/s/1qYtcu6K密碼: rr13

步驟如下:

1.蘋果電腦一般都安裝了python,在終端,輸“which python”或“which python3”,會(huì)顯示python的安裝目錄。

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

安裝方法:下載gz壓縮包,解壓后,會(huì)看到有個(gè)”setup.py” 文件,cd 進(jìn)去在終端下,輸入“pythonsetup.pyinstall”或“python3setup.pyinstall”.便可以安裝zope.interface。

如果出現(xiàn)

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

這一段錯(cuò)誤,因?yàn)閜ython路徑是在系統(tǒng)路徑下,默認(rèn)不能寫.(報(bào)錯(cuò)的原因就是因?yàn)闄?quán)限不夠)

解決方案:使用命令

sudopythonsetup.pyinstall

3.檢查下MAC有沒有自帶twisted。

檢查方法:打開python命令行,輸入“import twisted”,如果沒有任何提示,說明你已經(jīng)有twisted了,若提示沒有”twisted”模塊,則需要自己安裝twisted。

安裝方法:參考zope.interface的安裝,(如果權(quán)限不夠,同樣在命令之前加上sudo),安裝完成之后再用”import twisted”測(cè)試一下

出現(xiàn)下圖表示通過

之后就可以用命令,開啟服務(wù)了cd 進(jìn)去

python chatserver.py

1

一個(gè)小demo的實(shí)例程序:

方法2

iOS開發(fā)——socket服務(wù)器的搭建

字?jǐn)?shù)371閱讀1470評(píng)論8喜歡10

socket服務(wù)器可通過python來(lái)搭建

源程序分享在百度云,下載鏈接如下:

鏈接:http://pan.baidu.com/s/1o6Gk0u2密碼: fvju

在終端下,輸入:

pythonchatserver.py

便可以成功搭建socket服務(wù)器。(ps:該源碼只能在python2運(yùn)行環(huán)境成功執(zhí)行,python3雖然能連接但是無(wú)法發(fā)送數(shù)據(jù)。)

在iPhone測(cè)試連接socket服務(wù)器,源碼如下:

鏈接:http://pan.baidu.com/s/1gdAsYTd密碼: 684g

遇到的問題:沒有twisted模塊,需要自行安裝

安裝twisted步驟如下:

1.MAC系統(tǒng)一般已經(jīng)安裝了python,可以打開終端,輸“which python”或“which python3”,會(huì)顯示python的安裝目錄。(ps:對(duì)應(yīng)不同的python版本),如果沒有安裝,請(qǐng)自行谷歌或百度。

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

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

安裝方法:下載gz壓縮包,解壓后,會(huì)看到有個(gè)"setup.py" 文件,在終端下,輸入“pythonsetup.pyinstall”或“python3setup.pyinstall”.便可以安裝zope.interface。

3.檢查下MAC有沒有自帶twisted。

檢查方法:打開python命令行,輸入“import twisted”,如果沒有任何提示,說明你已經(jīng)有twisted了,若提示沒有"twisted"模塊,則需要自己安裝twisted。

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

安裝方法:參考zope.interface的安裝,安裝完成之后再用"import twisted"測(cè)試一下

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容