1### Answer to: "close connection socket python" ###
2
3sock.close();
4sock.shutdown(socket.SHUT_RDWR);
5
6###
7# sock.close():
8# Decrements the handle count by one and if the handle count has reached zero
9# then the socket and associated connection goes through the normal close
10# procedure (effectively sending a FIN / EOF to the peer) and the socket is
11# deallocated.
12#
13# Docs: https://docs.python.org/3/library/socket.html#socket.close
14# Close a socket file descriptor. This is like os.close(), but for sockets.
15# On some platforms (most noticeable Windows) os.close() does not work for
16# socket file descriptors.
17#
18#
19# sock.shutdown(socket.SHUT_RDWR):
20# For reading and writing closes the underlying connection and sends a FIN /
21# EOF to the peer regardless of how many processes have handles to the socket.
22# However, it does not deallocate the socket and you still need to call close
23# afterward.
24#
25#
26# Docs: https://docs.python.org/3/library/socket.html#socket.socket.shutdown
27# Shut down one or both halves of the connection. If how is SHUT_RD, further
28# receives are disallowed. If how is SHUT_WR, further sends are disallowed.
29# If how is SHUT_RDWR, further sends and receives are disallowed.
30###
1s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2s.connect(("10.0.0.3", 1234))
3# stuff here
4s.close() # this is how you close the socket