Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple way to simulate a slow network in python
    primarykey
    data
    text
    <p>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. </p> <p>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.</p> <p>But is there a better way of doing the slowdown? Perhaps by sending smaller packets, meaning I need to send more data?</p> <p>Any ideas on a good way to slow down one of the connections?</p> <p>Orjanp</p> <p>A simple client example with only one connection.</p> <pre><code>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() </code></pre> <p>A simple server listening to one port.</p> <pre><code>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() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload