python socket programming...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitheshsalian
    New Member
    • Mar 2008
    • 9

    python socket programming...

    hi,
    can anyone tell me how to receive the data from a particular sender using the recvfrom system call in python????

    i need the syntax(prototyp e) of the recvfrom call in python...

    if possible please give me an example...
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    This issue is related to Python, so moved this thread to Python forum

    Comment

    • Arnold Schuur
      New Member
      • Apr 2007
      • 36

      #3
      Originally posted by nitheshsalian
      hi,
      can anyone tell me how to receive the data from a particular sender using the recvfrom system call in python????

      i need the syntax(prototyp e) of the recvfrom call in python...

      if possible please give me an example...
      from socket import *
      Code:
      # Set the socket parameters
      host = "localhost"
      port = 21567
      buf = 1024
      addr = (host,port)
      
      # Create socket and bind to address
      UDPSock = socket(AF_INET,SOCK_DGRAM)
      UDPSock.bind(addr)
      
      # Receive messages
      while 1:
      	data,addr = UDPSock.recvfrom(buf)
      	if not data:
      		print "Client has exited!"
      		break
      	else:
      		print "\nReceived message '", data,"'"
      
      # Close socket
      UDPSock.close()
      Last edited by NeoPa; Mar 4 '08, 11:39 PM. Reason: Please use [CODE] tags

      Comment

      • nitheshsalian
        New Member
        • Mar 2008
        • 9

        #4
        wat if i want to receive the data from a particular client whose address is known???
        i want to receive data from a particular client whose address is known...
        wat other arguments should i add to tat system cal??



        Originally posted by Arnold Schuur
        from socket import *
        Code:
        # Set the socket parameters
        host = "localhost"
        port = 21567
        buf = 1024
        addr = (host,port)
        
        # Create socket and bind to address
        UDPSock = socket(AF_INET,SOCK_DGRAM)
        UDPSock.bind(addr)
        
        # Receive messages
        while 1:
        	data,addr = UDPSock.recvfrom(buf)
        	if not data:
        		print "Client has exited!"
        		break
        	else:
        		print "\nReceived message '", data,"'"
        
        # Close socket
        UDPSock.close()

        Comment

        • dazzler
          New Member
          • Nov 2007
          • 75

          #5
          Originally posted by nitheshsalian
          wat if i want to receive the data from a particular client whose address is known???
          i want to receive data from a particular client whose address is known...
          wat other arguments should i add to tat system cal??
          I think that you can't tell address who are you listening to, only the port what are you listening and that's enough

          when you have received message then you can block it if it's come from wrong ip address

          Comment

          • nitheshsalian
            New Member
            • Mar 2008
            • 9

            #6
            Originally posted by dazzler
            I think that you can't tell address who are you listening to, only the port what are you listening and that's enough

            when you have received message then you can block it if it's come from wrong ip address

            but tat recvfrom() system call does have tat sender's address option which means i can receive from a particular sender.....

            Comment

            Working...