Python Basic Socket network Demo

Publicado em: 18 Março 2015
no 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'))


Nesta página do site você pode assistir ao vídeo on-line Python Basic Socket network Demo duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Leigh 18 Março 2015, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,013 vezes e gostou 2 espectadores. Boa visualização!