Oct-14-2020, 10:12 AM
Hi
-------------------------------------------------
System Information
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Linux watvde0453 2.6.32-504.30.3.el6.x86_64 #1 SMP Thu Jul 9 15:20:47 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
CentOS release 6.8 (Final)
Linux lb-cam-bca-fsbackup 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
CentOS Linux release 7.6.1810 (Core)
Linux lb-cbga-eq 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
# python version 2
>>> sys.version
'2.7.5 (default, Dec 10 2013, 00:34:00) \n[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]'
# python version 3
>>> sys.version
('3.7.1 (default, Dec 7 2018, 02:32:23) \n'
'[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]')
-------------------------------------------------
Could someone clarify how a non-blocking socket connection is established, and also how to determine whether a socket is in blocking or non-blocking mode ?
From the documentation I see there is a setblocking() method that allows you to set the blocking mode.
However I am unclear where this needs to be set.
To use non-blocking sockets do I have to set the blocking mode to 0 on the (server side) listening socket, the client side connecting socket and the server side connecting socket as below:
Or do I need to set non-blocking on only a sub-set of these sockets ?
If all sockets involved need to have non-blocking mode explicitly set, what happens if one or end of the connection has blocking mode = 1 and the other end blocking mode = 0 ?
Once a connection is established is there anyway of determining whether the socket is in blocking or non-blocking mode from the socket object itself ?
Are there any differences in socket non-blocking configuration/behaviour between python 2.x and python 3.x ?
-------------------------------------------------
System Information
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Linux watvde0453 2.6.32-504.30.3.el6.x86_64 #1 SMP Thu Jul 9 15:20:47 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
CentOS release 6.8 (Final)
Linux lb-cam-bca-fsbackup 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
CentOS Linux release 7.6.1810 (Core)
Linux lb-cbga-eq 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
# python version 2
>>> sys.version
'2.7.5 (default, Dec 10 2013, 00:34:00) \n[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]'
# python version 3
>>> sys.version
('3.7.1 (default, Dec 7 2018, 02:32:23) \n'
'[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]')
-------------------------------------------------
Could someone clarify how a non-blocking socket connection is established, and also how to determine whether a socket is in blocking or non-blocking mode ?
From the documentation I see there is a setblocking() method that allows you to set the blocking mode.
However I am unclear where this needs to be set.
To use non-blocking sockets do I have to set the blocking mode to 0 on the (server side) listening socket, the client side connecting socket and the server side connecting socket as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# server side # server side listener listens = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listens.bind(( '127.0.0.1' , 1000 )) listens.listen( 5 ) listens.setblocking( 0 ) # set non blocking here # server side accepting connection while 1 : ... conn, addr = s.accept() conn.setblocking( 0 ) # set non blocking here ... # client side ... clientSocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) clientSocket.connect ((serverhost, serverport)) clientSocket.setblocking( 0 ) # set non blocking here ... |
If all sockets involved need to have non-blocking mode explicitly set, what happens if one or end of the connection has blocking mode = 1 and the other end blocking mode = 0 ?
Once a connection is established is there anyway of determining whether the socket is in blocking or non-blocking mode from the socket object itself ?
Are there any differences in socket non-blocking configuration/behaviour between python 2.x and python 3.x ?