Results 1 to 9 of 9
Hi there,
how are u all doing?
I am writing a simple UDP server, and I have a quick question, I want my server to serve only one client at ...
- 11-20-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 35
writting a simple UDP server, a little help please?
Hi there,
how are u all doing?
I am writing a simple UDP server, and I have a quick question, I want my server to serve only one client at a time, but I really have no idea where to start, any tips on how to do that, is there a specific function i should use, like for example, connect?
I googled it but to no avail!!
any help is appreciated!!
thank u in advance
- 11-20-2009 #2
- 11-20-2009 #3Just Joined!
- Join Date
- May 2009
- Posts
- 35
I am writing my program in C, and sorry if its in the wrong forum, i was confused on where to ask my question, but thought since its mostly a programming question i should put it here
- 11-20-2009 #4
woops my bad its the right section.. I thought it said ubuntu.. (sorry :P I was mistaken with a diffrent one)
Edit:
Leeched:
Does that help?Code:/* Sample UDP server */ #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> int main(int argc, char**argv) { int sockfd,n; struct sockaddr_in servaddr,cliaddr; socklen_t len; char mesg[1000]; sockfd=socket(AF_INET,SOCK_DGRAM,0); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr=htonl(INADDR_ANY); servaddr.sin_port=htons(32000); bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)); for (;;) { len = sizeof(cliaddr); n = recvfrom(sockfd,mesg,1000,0,(struct sockaddr *)&cliaddr,&len); sendto(sockfd,mesg,n,0,(struct sockaddr *)&cliaddr,sizeof(cliaddr)); printf("-------------------------------------------------------\n"); mesg[n] = 0; printf("Received the following:\n"); printf("%s",mesg); printf("-------------------------------------------------------\n"); } }
- 11-20-2009 #5Just Joined!
- Join Date
- May 2009
- Posts
- 35
unfortionatly no, as I stated before I already googled it, and came by a couple of examples on how to write a UDP server, my question is, how can we make a server handle only one client at a time, is there a function that does that?
or does
solve this problem?Code:bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
This is my first time I am writing a server so if I ask a stupid question go easy on me
- 11-20-2009 #6
unless you specifically write your code to use threads, it will only serve one at a time
- 11-20-2009 #7Just Joined!
- Join Date
- May 2009
- Posts
- 35
- 11-20-2009 #8
blocking socket can only read from one source at a time
- 11-20-2009 #9Just Joined!
- Join Date
- May 2009
- Posts
- 35
thanks to all who replied, i think i got it now =)
just one last question, since i dont want to wast another post on it, what is best way in your opinion to deal with packet reordering?
thank u in advance


Reply With Quote

