🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Question about winsock TCP/IP

Started by
8 comments, last by Have a nice day 23 years, 6 months ago
Hello I have 2 question about TCP/IP first, is there possible to establish TCP/IP connection when using peer-to-peer mode, I mean connectionless socket; second, how do you send/recv large amount of data, in case a file. Will you send/recv with fixed small size buffer, or send/recv with the original size of the data and wait the return value from send()/recv() function and send again?
Advertisement
I''m not too sure about this, but if you use UDP (user datagram protocol I think) instead of TCP/IP then you don''t need connections. But I''m not very sure on how this protocol works as I''m quite new to it, anyone care to elaborate?

Trying is the first step towards failure.
Trying is the first step towards failure.
1) UDP sockets are normally connectionless. You would just use the sendto() and recvfrom() methods instead of send() and recv(). They have an extra argument that stores the source / destination of the send.

2) It differs. With TCP, you can just issue a send() with the entire file contents, with UDP, 1 send = 1 packet, so if your file is larger than the maximum packet size that the network can deliver, you''ll get an error returned. So for UDP you have to break the file up into many send calls, but you''ll have to also worry about resending lost packets, and ordering.
So it is impossible to get a TCP/IP and a connectionless socket at the same time, right?
UDP (though not in the name) is part of the TCP/IP standard.

You can have many connectionless & many connections concurrently.

You can have a tcp (connection) & udp (connectionless) sockets at the same time, even several of each. </i> <br><br>Magmai Kai Holmlor<br>- The disgruntled & disillusioned<br>
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Hi,

I believe Winsock has the concept of "connected UDP". Basically you connect tell Winsock what address you want to send UDP packets to and from then on you can use send()/recive() instead of sendto()recvfrom(). I don''t know if this exists for the more tradistional Unix implementations of Sockets.

-Daedalus
DM's Rules:Rule #1: The DM is always right.Rule #2: If the DM is wrong, see rule #1.
There are 2 winsock protocols for IP (not counting RAW)

TCP
1)Stream based
2)Doesn''t preserve send boundaries (1 send may = man recvs)
3)reliable delivery
4)sequential

UDP
1)Datagram based
2)preserves send boudaries (1 send = 1 recv)
3)unreliable delivery (packets may be dropped based on network conditions etc...)
4)non-sequential (packets may arrive out of order to the receiving machine)

If you want to add a feature of one protocol to the other, you have to add it in your code. If you''re doing something like sending a file, use a TCP socket. A common phrase on the winsock mailing list is "don''t reinvent the wheel." For some reason, everyone always wants to add a reliability to UDP for things that would be better suited to TCP in the first place.

-Jon
Sorry, never meant to imply that you could get any gauranteed delivery of the UDP protocol or anything. I was just saying that I believe I remember seeing a setting in winsock to declare the system your sending UDP packets to once and have the API save that info so that you could use simple send()/recv() commands instead of sendto()/recvfrom(). Didn''t mean to cause any confusion.

-Daedalus
DM's Rules:Rule #1: The DM is always right.Rule #2: If the DM is wrong, see rule #1.
You''re right Daedalus, you can call connect() on a UDP socket to create a connection. I was sortof answering "Have a Nice Day"s question, and trying to get him to rethink what he needs.

From questions here and on the mailing list, many people would do something like add a reliability layer to UDP for 1 function, like sending a file, when the easiest thing to do would be to just use TCP.
I can see adding a limited amount of reliablity (like doing a full reliability check for every nth packet). But, your right, it wouldn''t make much sense to go to all the effort to add full reliability to UDP just for one function.

-Daedalus
DM's Rules:Rule #1: The DM is always right.Rule #2: If the DM is wrong, see rule #1.

This topic is closed to new replies.

Advertisement