码迷,mamicode.com
首页 > 编程语言 > 详细

用PYTHON硬写SOCKET

时间:2015-11-24 20:15:42      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

这个文章的系列很有意思,练练~~:

http://python.jobbole.com/82763/

:)

第一步,最简单的SERVER和CLIENT。感觉和写JAVA,C的最简单的一样一样的,,看来,我只会最简单的?:)

server.py及client.py

#Pserver
import socket

HOST = ‘‘
PORT = 8088

reply = Yes

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
print Pserver start listen...

s.listen(3)

conn, addr = s.accept()
request = conn.recv(1024)

print request is: , request
print Connect by , addr

conn.sendall(reply)

conn.close()
#Pclient
import socket

HOST = 127.0.0.1
PORT = 8088

request = cat you hear me?

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

s.sendall(request)

reply = s.recv(1024)
print reply is: , reply
s.close()

技术分享

用PYTHON硬写SOCKET

标签:

原文地址:http://www.cnblogs.com/aguncn/p/4992605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!