Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hunryzh2003 committed Nov 20, 2014
0 parents commit 4a9c04d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Empty file added README.md
Empty file.
19 changes: 19 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python
import time
import socket
import re

s = socket.socket()
host = socket.gethostname()
port = 12345

s.connect((host, port))
s.send('PING\r')
recv_line = s.recv(1024)
print recv_line
matchObj = re.match(r'.* (\d+\.?\d*)', recv_line)
if matchObj:
print matchObj.group(1)
else:
print 'not matched'
s.close
22 changes: 22 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python
import time
import socket

s = socket.socket()
host = socket.gethostname()
port = 12345
s.bind((host, port))

s.listen(5)
while True:
c, addr = s.accept()
print 'Got connection from', addr
while True:
recv_line = c.recv(1024)
print recv_line
if recv_line == 'PING\r':
time_s = str(time.time())
c.send('PONG ' + time_s)
break
c.close()
break

0 comments on commit 4a9c04d

Please sign in to comment.