Skip to content

Commit 15688a2

Browse files
committed
Create echo_client.py
1 parent 0506d3c commit 15688a2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

socket/echo_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
'a socket example which send echo message to server.'
5+
6+
import socket
7+
8+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9+
# 建立连接:
10+
s.connect(('127.0.0.1', 9999))
11+
# 接收欢迎消息:
12+
print s.recv(1024)
13+
for data in ['Michael', 'Tracy', 'Sarah']:
14+
# 发送数据:
15+
s.send(data)
16+
print s.recv(1024)
17+
s.send('exit')
18+
s.close()

0 commit comments

Comments
 (0)