Should I change socket options on the original socket or the new one?

Viewed 12

Consider the following python script:

import socket
import time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 9999))
s.listen()
connections = []

while True:
    time.sleep(1)
    conn, addr = s.accept()
    connections.append(conn)
    # send and receive data using open connections

According to the socket documentation:

socket.accept()

Accept a connection. The socket must be bound to an address and listening for connections. The return value is a pair (conn, address) where conn is a new socket object usable to send and receive data on the connection, and address is the address bound to the socket on the other end of the connection.

Now suppose I want to change the socket options, like:

setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2048) 

Should I call this method on the original socket s, the new connection conn or both of them?

0 Answers
Related