python recvfrom not working when on different ip

Discussion in 'General Networking Discussion' started by ambu.sreedharan, Jun 15, 2011.

  1. ambu.sreedharan

    ambu.sreedharan

    Joined:
    Jun 15, 2011
    Messages:
    2
    Likes Received:
    0
    Location:
    Englewood, CO
    Ok so i am a newbie into networking.
    I wrote a python script to be a client and another python script to be a server. I used UDP sockets inside both and used sento and recvfrom to post and receive. No when i have both the client and server on the same system using localhost as the host, messages are transferred with ease. Now when I put the server script on a actual server, it does not receive. I put the host ids on both the scripts as the IP of the server. I tried tcpdump and found out that messages are actually sent to the destination port and netstat confirms that the port is listening. Now here is a little twist the server has 3 interfaces.. eth1 , eth0 and lo. I dont know how to specify what to aim at but i know tcpdump shows that eth0 is the one thats getting messages. I tried with the IP's of both interfaces and still doesn't work. I cant understand how can a port listen and get messages but still not show it.

    here is the code:
    //Server

    import socket,struct,IN
    # Set the socket parameters
    host = "10.73.***.**"
    port = 45333
    buf = 1029
    addr = (host,port)

    # Create socket and bind to address
    UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)


    UDPSock.bind(addr)

    # Receive messages
    while 1:
    data,addr = UDPSock.recvfrom(buf)
    if not data:
    print "Client has exited!"
    else:
    print "\nReceived message '", data,"'"

    # Close socket
    UDPSock.close()

    *****************************************************
    //client
    import socket

    MCAST_GRP = '10.73.***.**'
    MCAST_PORT = 45333

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    #sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
    while 1:
    sock.sendto("robot", (MCAST_GRP, MCAST_PORT))


    **********************************************************

    SOMEBODY PLEASE HELP.
     
    ambu.sreedharan, Jun 15, 2011
    #1
    1. Advertisements

  2. ambu.sreedharan

    ambu.sreedharan

    Joined:
    Jun 15, 2011
    Messages:
    2
    Likes Received:
    0
    Location:
    Englewood, CO
    Another update here. I tried the same client server code on another network and it worked just like the way it should. But it just doesnt work in one network. I just can't guess what could be the problem. Is it some configuration in the network??
     
    ambu.sreedharan, Jun 16, 2011
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.