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


PYTHON examples » Network » Socket Pocket »

 

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



import socket

HOST = "127.0.0.1"
PORT = 5000

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

while 1:
   packet = raw_input"Packet>>>" )
   print "nSending packet containing:", packet
   mySocket.sendtopacket, HOST, PORT ) )
   print "Packet sentn"

   # step 3: receive packet back from server
   packet, address = mySocket.recvfrom1024 )
   print "Packet received:"
   print "From host:", address]
   print "Host port:", address]
   print "Length:", lenpacket )
   print "Containing:"
   print "t" + packet + "n"

mySocket.close()

           
       



Leave a Comment / Note


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


PYTHON examples

 Navioo Network
» Socket Pocket