TFTP connection problem

This is a discussion on TFTP connection problem within the C Programming forums, part of the General Programming Boards category; Hello everyone, I want to implement simple TFTP protocol, but I have problem: Client send request to the server, where ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    45

    TFTP connection problem

    Hello everyone,

    I want to implement simple TFTP protocol, but I have problem:
    Client send request to the server, where the server port is 69. Then server sends back 512 bytes of data, or an ACK. But , server is not sending data on 69 , but on new port (TID). (RFC 1350)

    Must I have two different sockets for this? Two connections, two binds?
    When I duplicate all, I have also problems, they can not communicate.

    They communicate just if the client and the server have the same port: 69 ! Why ?

    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Trivial File Transfer Protocol - Wikipedia, the free encyclopedia
    Port 69 is used to just establish a connection.
    A chosen port is used for a single file transfer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    45
    I dont know how to achieve this with sockets :

    For example, suppose the TFTP client selects a TID of 3,145 for its initial message. It would send a UDP transmission from its port 3,145 to the server's port 69. Say the server selects a TID of 1,114. It would send its reply from its port 1,114 to the client's port 3,145. From then on, the client would send messages back to server port 1,114 until the TFTP session was completed.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    So are you writing a client, a server, or both?

    Server creates a socket on port 69, binds to it, starts listening to it.
    For each accept, it creates a new temporary socket, and uses that to send a message back to the originating IPort

    If you haven't read this yet, you should.
    Client-Server Background
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    use 'recvfrom' and 'sendto' instead of 'recv' and 'send'. then you always have a destination or source address in the call.

    client:
    sendto(...,server at port 69)
    recvfrom(...,server address (port 1114 in your example))
    save address that server sent
    sendto(...,server at 1114)

    server
    bind socket to port 69
    recfrom(socket69,...,client address)
    create new socket
    sendto(new socket,...,client address) // the system will assign an unused port for you. you don't need to bind this new socket
    recvfrom(new socket,...,client address)
    ...

    if your server is single threaded, it just just loop using the new socket until the transfer is completed, then go back to recvfrom on port 69.

  6. #6
    Registered User
    Join Date
    Jul 2012
    Posts
    45
    I'm writing both , server and client...and I will do it on this way. First it will be single threaded, then with threads. I hope so

    Thanks a lot, Salem and dmh2000! This is helpful for start

  7. #7
    Registered User
    Join Date
    Jul 2012
    Posts
    45
    I have done this steps, and now I have this problem:

    client

    1. Socket sfd -> OK
    2. srv_address.sin_port = htons(port); // port = 69 ->OK
    3. Connect sfd -> OK
    4. Sendto server at 69 -> OK
    5. recvfrom server , can not receive ???
    6. save server's address
    7. send to server at new port

    server

    1. Socket sfd -> OK
    2. srv_address.sin_port = htons(port); // port = 69 -> OK
    3. bind to 69 -> OK
    4. recv from sfd -> OK
    5. New socket sfd2, srv_address.sin_port = htons(new_port); -> OK
    6. sendto (new socket, client address) -> OK
    7. recvfrom (new socket, client address)

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    do you get an error at client 5. recvfrom or it just doesn't receive anything?

    can you post your code if it isn't too complex

  9. #9
    Registered User
    Join Date
    Jul 2012
    Posts
    45
    Hi, I have managed to fix it, it was problem with ports,my fault with bind ....thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tftp server
    By kiros88 in forum Linux Programming
    Replies: 2
    Last Post: 04-12-2010, 10:18 AM
  2. sql connection problem
    By arian in forum C# Programming
    Replies: 0
    Last Post: 08-15-2008, 12:43 PM
  3. Connection problem
    By Tommo in forum Tech Board
    Replies: 9
    Last Post: 10-03-2007, 12:45 PM
  4. Weird connection problem.
    By tilex in forum Networking/Device Communication
    Replies: 6
    Last Post: 02-06-2005, 09:11 AM
  5. Open Source Tiny Simple TFTP Server
    By DeepBlackMagic in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2004, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21