HELP!!! How do I send an ACK packet in UDP?????

Discussion in 'Python' started by myersoft@gmail.com, Jul 25, 2006.

  1. Guest

    I need my udp server to send an ACK back to the client when it
    successfully receives data from the client to let it know not to retry
    the send (yes, I do know this is how TCP works but must be in UDP)
    I am using this example code I found on the net for the server, I need
    to figure out how to get the ip and port that the client transmitted
    from and return an ack response. Any help would be greatly
    appreciated..........

    from socket import *

    # 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()
    , Jul 25, 2006
    #1
    1. Advertising

  2. Joe Knapka Guest

    wrote:

    > I need my udp server to send an ACK back to the client when it
    > successfully receives data from the client to let it know not to retry
    > the send (yes, I do know this is how TCP works but must be in UDP)
    > I am using this example code I found on the net for the server, I need
    > to figure out how to get the ip and port that the client transmitted
    > from and return an ack response. Any help would be greatly
    > appreciated..........
    >
    > from socket import *
    >
    > # 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)


    Um... There's the sender's address, right there,
    per the documentation for recvfrom(), which you
    seem to have read, since you know recvfrom()
    returns a 2-item sequence.

    No doubt you realized that seconds after hitting
    "send".

    -- JK
    Joe Knapka, Jul 25, 2006
    #2
    1. Advertising

  3. Joe Knapka Guest

    wrote:

    > I need my udp server to send an ACK back to the client when it
    > successfully receives data from the client to let it know not to retry
    > the send (yes, I do know this is how TCP works but must be in UDP)
    > I am using this example code I found on the net for the server, I need
    > to figure out how to get the ip and port that the client transmitted
    > from and return an ack response. Any help would be greatly
    > appreciated..........
    >
    > from socket import *
    >
    > # 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)


    Um... There's the sender's address, right there,
    per the documentation for recvfrom(), which you
    seem to have read, since you know recvfrom()
    returns a 2-item sequence.

    No doubt you realized that seconds after hitting
    "send".

    -- JK
    Joe Knapka, Jul 25, 2006
    #3
  4. Guest

    Yes, you were right it was already there (sorry, my mistake), the
    bigger problem is how do I send an ack packet????????

    Joe Knapka wrote:
    > wrote:
    >
    > > I need my udp server to send an ACK back to the client when it
    > > successfully receives data from the client to let it know not to retry
    > > the send (yes, I do know this is how TCP works but must be in UDP)
    > > I am using this example code I found on the net for the server, I need
    > > to figure out how to get the ip and port that the client transmitted
    > > from and return an ack response. Any help would be greatly
    > > appreciated..........
    > >
    > > from socket import *
    > >
    > > # 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)

    >
    > Um... There's the sender's address, right there,
    > per the documentation for recvfrom(), which you
    > seem to have read, since you know recvfrom()
    > returns a 2-item sequence.
    >
    > No doubt you realized that seconds after hitting
    > "send".
    >
    > -- JK
    , Jul 25, 2006
    #4
  5. Joe Knapka Guest

    wrote:

    > Yes, you were right it was already there (sorry, my mistake), the
    > bigger problem is how do I send an ack packet????????


    Look at the docs for socket.sendto(). Of course, deciding
    what data should be in your "ACK" packet is for you to decide.

    Cheers,

    -- JK
    Joe Knapka, Jul 26, 2006
    #5
  6. Rob Sinclar Guest

    On Wednesday 26 July 2006 00:48, wrote:
    > how do I send an ack packet????????


    UDP stands for User Datagram Protocol. Ther'es no ack like in TCP.
    Define your own protocol ie when machine1 sends the string "ACK",
    machine2 has the acknowledge it wanted.

    Regards,
    Rob
    Rob Sinclar, Jul 26, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom St Denis

    Re: How to format/send/receive UDP packet in C?

    Tom St Denis, Jun 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    3,067
    Tom St Denis
    Jun 24, 2003
  2. Replies:
    0
    Views:
    1,864
  3. Rahul Gandhi

    Re: How to format/send/receive UDP packet in C?

    Rahul Gandhi, Jun 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    8,770
    Rahul Gandhi
    Jun 24, 2003
  4. Tom St Denis

    Re: How to format/send/receive UDP packet in C?

    Tom St Denis, Jun 24, 2003, in forum: C Programming
    Replies:
    11
    Views:
    8,472
    Chris Torek
    Jun 26, 2003
  5. Li Han
    Replies:
    2
    Views:
    505
    bobicanprogram
    Feb 9, 2009
Loading...

Share This Page