Many python modules which give access to application layer networking services
Sometimes you may have to implement your own application layer protocol. In this type of case you have to use sockets(a Transport Layer Service)
import sys
from socket import *
serverHost = ’localhost’
serverPort = 2000
# create a TCP socket
s = socket(AF_INET, SOCK_STREAM)
s.connect((serverHost, serverPort))
s.send(’Hello world’)
data = s.recv(1024)
print data
from socket import *
myHost = ’’
myPort = 2000
# create a TCP socket
s = socket(AF_INET, SOCK_STREAM)
# bind it to the server port number
s.bind((myHost, myPort))
# allow 5 pending connections
s.listen(5)
while 1:
# wait for next client to connect
connection, address = s.accept()
while 1:
data = connection.recv(1024)
if data:
connection.send(’echo -> ’ + data)
else:
break
connection.close()
2 comments:
nice blog
its very usefull to me
Good info...
keep posting
Post a Comment