Created
December 2, 2017 11:55
-
-
Save tenfyzhong/340c56322dda6aff87c1339c0c985ce0 to your computer and use it in GitHub Desktop.
example
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import socket | |
import time | |
HOST = 'localhost' | |
PORT = 1680 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((HOST, PORT)) | |
s.setsockopt(socket.SOL_TCP, socket.TCP_QUICKACK, 1) | |
s.send('hello') | |
s.recv(1024) | |
s.close() | |
time.sleep(1) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import socket | |
HOST = 'localhost' | |
PORT = 1680 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((HOST, PORT)) | |
s.listen(5) | |
while True: | |
conn, addr = s.accept() | |
while True: | |
data = conn.recv(1024) | |
conn.setsockopt(socket.SOL_TCP, socket.TCP_QUICKACK, 1) | |
conn.send(data) | |
print data | |
if not data: | |
break | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment