Python网络编程2
python网络编程之socket
code
(server2.py) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| #!/usr/bin/env python
'''#/*=============================================================================
#
# Author: mengdaikun - mengdaikun@gmail.com
#
# QQ : 646978600
#
# Last modified: 2013-04-09 15:37
#
# Filename: server2.py
#
# Description:
#
#=============================================================================*/'''
# basic server by python
import os , sys , socket
host = ''
port = 5566
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind((host,port))
print "Waiting for connecting..."
s.listen(5)
while 1:
clientsock , clientaddr = s.accept()
print "Got connect from",clientsock.getpeername()
clientsock.close()
|