-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hunryzh2003
committed
Nov 20, 2014
0 parents
commit 4a9c04d
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |