Python Basic Socket network Demo

Pubblicato il: 18 marzo 2015
sul canale di: 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'))


In questa pagina del sito puoi guardare il video online Python Basic Socket network Demo della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Leigh 18 marzo 2015, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,013 volte e gli è piaciuto 2 spettatori. Buona visione!