Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WINSOCK MATTERS - UDP or TCP 1

Status
Not open for further replies.

castor2003

Programmer
Jul 5, 2003
115
0
0
LC
I am writing an app which comprises an Application Manager and a Library Kiosk. I am using Winsock.ocx to send instructions to the Kiosk like when to shut down temporarily and reopen etc. In the protocol selection I get 0 for TCP and 1 for UDP. I have been using 1, cause I see it on most examples I have read. But I am still the dark as to when I should use TCP over UDP. Any help?
 
If you are carrying on a conversation with the server, you need the TCP connection-oriented protocol. (Unless the server sends responses via a seperate UDP connection)

If you are sending information to the server without getting any responses, UDP can be used.

However, in either case, you must use the protocol the server was designed to use.
 
This is what we had to say about it in MegaFox: 1002 Things You Wanted to Know About Extending VFP:

• User Datagram Protocol (UDP) A connectionless protocol (analogous to passing a note) under which data is passed from one ‘peer’ computer to another without the need to establish an explicit connection.
• Transmission Control Protocol (TCP) A connection based protocol (analogous to a telephone call) which requires that a connection be explicitly established between one computer acting as the ‘client’ and another computer acting as the ‘host’.

So which protocol is best?

The answer, as so often in VFP, is that it depends. Each protocol has its benefits, and its drawbacks. Table 9.12 gives a side-by-side comparison.

Table 9.12: Features of the protocols available to the winsock control
UDP TCP
No connection required. Participating computers are equivalent to each other and each binds to the remote port of its peer Explicit connection required. One participant (the ‘host’) must have an active listener so that a client can establish a connection
Data must be transmitted in a single send operation. Maximum size is determined by the network set up and excess data is simply lost. Data can be transmitted using multiple send operations. Maximum size is not dependent upon network configuration
A single socket can switch between partners without needing to reset A single socket can only handle one connection at a time. Therefore to change partners any existing connection must be closed before another can be established
No acknowledgements Explicit connection allows query/acknowledgement to control communication
No connection and no integrity checking Connection is managed and data integrity ensured
Lower resource requirement, unreliable Higher resource requirement, reliable

It is apparent from the above table that the UDP protocol is better suited to applications that either involve manual intervention (e.g. Instant Messaging) or are simply broadcast without requiring any acknowledgement. Conversely, TCP is a better choice when an automated process is required (e.g. Error Reporting) or when any form of exchange is required.


Marcia G. Akins
 
Great guys. The basic difference is the need for feedback. In my case my client just follows instructions. I need hear nothing from him. Good reading Marcia, but it did not appear in table form as you intended. Try reposting with the (
Code:
) before and (
) after the table. Ignore the () in this post only us the [[]] brackets.
 
One more thing, How do I ensure that no one else sends instructions to the Kiosk on the Network, using a similar WINSOCK setup..

See I just moved to WINSOCK I was using a timer on the client which responds to the contents of a shared table.

Could someone rest my fears?


 
Marcia,

Star worthy. Your books have proved invaluable to me time and again. Thank you.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
You mean like table locking? So the server only serves your client, or one client at a time?

or perhaps Authentication? Require a Password (or a Challenge-Response authentication)

The server should be able to respond to multiple TCP connections at the same time.
 
WGCS

I am using UDP. I want to ensure that the client only respond to my connection only.

is .accept() the answer. My code is in .dataarrival()

Any help.
 
I'm not sure the best way:

There's probably a way in Accept() to deny connections based on originating IP address, and only accept ones coming from your machine.

Alternatively, you could have a particular password as part of the command, and accept all UDP packets coming on the particular port, but only react to those that have the right password. The password could be a permutation of the current date, so that if someone sniffs the packets, and imitates the client, then their hack would not work the next day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top