socket服務器的搭建-Mac

原文:http://m.blog.csdn.net/article/details?id=51126881


socket服務器可通過python來搭建
在終端輸入命名:

python chatserver.py

看到提示: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” 文件,在終端下,輸入“python setup.py install”或“python3 setup.py install”.便可以安裝zope.interface。
如果出現

error: can't create or remove files in install directory 
The following error occurred while trying to add or remove files in 
the installation directory: 
[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/ 
test-easy-install-411.write-test' 
The installation directory you specified (via --install-dir, --prefix, 
or the distutils default setting) was: 
    /Library/Python/2.7/site-packages/ 
**Perhaps your account does not have write access to this directory?**  If 
the installation directory is a system-owned directory, you may need to 
sign in as the administrator or "root" account.  If you do not have 
administrative access to this machine, you may wish to choose a different 
installation directory, preferably one that is listed in your PYTHONPATH 
environment variable. 
For information on other options, you may wish to consult the 
documentation at: 
  http://peak.telecommunity.com/EasyInstall.html 
Please make the appropriate changes for your system and try again.

這一段錯誤,因爲python路徑是在系統路徑下,默認不能寫.(報錯的原因就是因爲權限不夠)
解決方案:使用命令

sudo python setup.py install

3.檢查下MAC有沒有自帶twisted。
檢查方法:打開python命令行,輸入“import twisted”,如果沒有任何提示,說明你已經有twisted了,若提示沒有”twisted”模塊,則需要自己安裝twisted。
安裝方法:參考zope.interface的安裝,(如果權限不夠,同樣在命令之前加上sudo),安裝完成之後再用”import twisted”測試一下
出現下圖表示通過
測試
之後就可以用命令,開啓服務了

python chatserver.py

一個小demo的實例程序:
效果圖
地址:github




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章