|
-
July 1st, 2009, 06:04 AM
#1
udp client and server
Hi All,
Im new about network programming and I have some troubles about it. The thing that I want to do, client first sends data to the server than waits for ACK message. the examples that I find, only waits for a message or sends messages, not both..
thanks if anyone can help...
-
July 1st, 2009, 07:28 AM
#2
Re: udp client and server
You should not be using UDP for something like this. It is (by design) an unreliable protocol and if you go through all the work of trying to make it reliable by sending ACKs back and forth, then you've just made a more complicated and non-standard form of TCP. Use TCP instead. Thousands of programmer man-hours have already gone into it.
-
July 1st, 2009, 08:50 AM
#3
Re: udp client and server
I know that TCP use ack messages for reliable transmitting but my aim is different, I will design a discovery protocol and I need to do it with udp datagrams, and ACK message will contain encrypted text for authentication, I mean not like exactly TCP's ack messages...
thanks for reply...
-
July 1st, 2009, 02:42 PM
#4
Re: udp client and server
Since there is no "connection" between a UDP server and a client (and not a well-defined idea as to what it means to be a "server" or "client" with respect to UDP), then data exchange gets complicated. Because there is no "connection" information associated with UDP, recvfrom() and sendto() must be used as they have the extra sockaddr parameter to indicate where the packet came from/goes to.
Your brief description above indicates that you probably plan on sending out a broadcast and see who answers, right? In essence, the machine that sends the broadcast is the client in this scenario and each potential receiver of the broadcast must act as a server of sorts "listening" (I put that in scare quotes because you don't really listen() with UDP) for a UDP packet from the broadcaster. Is this an accurate assessment of your goal?
-
July 3rd, 2009, 11:10 AM
#5
Re: udp client and server
yea it won't be broadcast exactly but the idea is smilar. Server will send a message and if the client recieves that message - will reply server's message (ack),, as you said.. so how can I do such a program ? there are any examples ?
Last edited by sezar355; July 4th, 2009 at 03:53 AM.
-
July 6th, 2009, 08:43 AM
#6
Re: udp client and server
OK, if you're not sending a broadcast, then you must have a sockaddr struct for each machine you are using sendto() to "send to." Why can't you recvfrom() using the same socket and sockaddr?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|