import socket
ip='0.0.0.0'
port=8888
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
server.bind((ip,port))
server.listen(5)
print "Listning on %s %s" %(ip,port)
(obj,cliente)=server.accept()
print "Conexion recived from %s" %cliente[0]
while True:
msg=obj.recv(1024)
print msg
server.close()
except Exception as erro:
print erro
server.close()
No idea about python , but what you indicate are POSIX socket handling functions for working with network connections:
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
Function to create a socket , a connector to be able to make network connections.
socket.AF_INET
is the domain of the connector. In this case, an IPv4 socket.socket.SOCK_STREAM
type of the connector, dependent on the previous parameter (not all domains support the same types ). In this case, a type connectorSTREAM
: using the TCP protocol , which provides certain security guarantees: packets arrive in order, discarding repeated and/or damaged ones.server.bind((ip,port))
Associates the connector with the indicated IP address and port . Check that they are available, and reserve them for us.
server.listen(5)
Puts the connector in listening mode . From this moment, connection requests are accepted in it.
The number
5
indicates the capacity of the pending connections queue . If the queue is full and there are more connection requests, they are discarded.