Set up a server that will receive packets from a client and send packets to a client. : Socket Pocket : Network PYTHON examples


PYTHON examples » Network » Socket Pocket »

 

Set up a server that will receive packets from a client and send packets to a client.



import socket

HOST = "127.0.0.1"
PORT = 5000

mySocket = socket.socketsocket.AF_INET, socket.SOCK_DGRAM )

mySocket.bind( ( HOST, PORT ) )

while 1:
   packet, address = mySocket.recvfrom1024 )

   print "Packet received:"
   print "From host:", address]
   print "Host port:", address]
   print "Length:", lenpacket )
   print "Containing:"
   print "t" + packet

   # step 4: echo packet back to client
   print "nEcho data to client...",
   mySocket.sendtopacket, address )
   print "Packet sentn"

mySocket.close()


           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Network
» Socket Pocket