Python Basic Socket network Demo

Publicado el: 18 marzo 2015
en el canal de: Leigh
1,013
2

Just testing the "socket" module for networking in Python



server.py

import time
import socket

creating a socket object
s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)

get local Host machine name
host = socket.gethostname()
port = 9999

bind to pot
s.bind((host, port))

que up to 5 requests
s.listen(5)

while True:
establish connection
clientSocket, addr = s.accept()
print("got a connection from %s" % str(addr))
currentTime = time.ctime(time.time()) + "\r\n"
clientSocket.send(currentTime.encode('ascii'))
clientSocket.close()


client.py

import socket

s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)

host = socket.gethostname()
port = 9999

s.connect((host, port))

tm = s.recv(1024)

s.close()
print("the time we got from the server is %s" % tm.decode('ascii'))


En esta página del sitio puede ver el video en línea Python Basic Socket network Demo de Duración hora minuto segunda en buena calidad , que subió el usuario Leigh 18 marzo 2015, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,013 veces y le gustó 2 a los espectadores. Disfruta viendo!