-
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
-
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.
-
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.
-
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 IP:port
If you haven't read this yet, you should.
Client-Server Background
-
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.
-
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 :D
-
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)
-
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
-
Hi, I have managed to fix it, it was problem with ports,my fault with bind ....thank you.