Scenario. I have a client with two network connections to a server. One connection uses a mobile phone, and the other is using a wlan connection.
The way that I have solved this is by having the server listen at two ports. But, the mobile connection should be slower than the wlan connection. The data that is sent, is usually just a line of text. I have solved the slower connection issue by allowing the mobile connection to send data in a five second interval, the wlan connection have an interval of one second.
But is there a better way of doing the slowdown? Perhaps by sending smaller packets, meaning I need to send more data?
Any ideas on a good way to slow down one of the connections?
Orjanp
A simple client example with only one connection.
def client():
import sys, time, socket
port = 11111
host = '127.0.0.1'
buf_size = 1024
try:
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mySocket.connect((host, port))
except socket.error, (value, message):
if mySocket:
mySocket.close()
print 'Could not open socket: ' + message
sys.exit(1)
mySocket.send('Hello, server')
data = mySocket.recv(buf_size)
print data
time.sleep(5)
mySocket.close()
client()
A simple server listening to one port.
def server():
import sys, os, socket
port = 11111
host = ''
backlog = 5
buf_size = 1024
try:
listening_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
listening_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
listening_socket.bind((host, port))
listening_socket.listen(backlog)
except socket.error, (value, message):
if listening_socket:
listening_socket.close()
print 'Could not open socket: ' + message
sys.exit(1)
while True:
accepted_socket, adress = listening_socket.accept()
data = accepted_socket.recv(buf_size)
if data:
accepted_socket.send('Hello, and goodbye.')
accepted_socket.close()
server()