LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 08-21-2003, 11:43 AM   #1
Pres
Member
 
Registered: Jun 2002
Location: Australia
Distribution: Slack 9.1
Posts: 232
Thanked: 0
sockets, UDP, using select()


[Log in to get rid of this advertisement]
I am using select() both on my server and clients, prior to any recvfrom() or sendto() ... testing read and write flags accordingly.

Am I doing the right thing here ? Any info greatly appreciated.
Pres is offline     Reply With Quote
Old 08-21-2003, 02:26 PM   #2
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201
Thanked: 0
See:
Code:
    ....
    fd_set rfds;
    struct timeval tv;
    struct sockaddr_in client;
    int a=sizeof(client);
    tv.tv_sec=0;
    tv.tv_usec=0;
    FD_ZERO(&rfds);
    FD_SET(fd,&rfds);
    while (select(fd+1,&rfds,0,0,&tv))
    {
        if ((l=recv_packet(packet,256,(struct sockaddr*)(&client),&a,0,0,&s))==-1)
            return;

        last_packet_came=get_time();
 
        switch(*packet) {
           .....
        }
The code I put here, is a part of the main server.c loop of the game 0verkill-0.16. As you can see the author explicitly callled select, before receiving data from client(s). recv_packet is something implimented by recvfrom plus some crc checks (it's a local function). That `while' you can see, is the main loop of the server. It means till when something is sent, do the cycle (clear?). FD_XXX are all macros, for example FD_SET as far as I know, is for adding a socket file descriptor to your fd set. You can find more details on man pages.

Last edited by Mohsen; 08-21-2003 at 02:28 PM..
Mohsen is offline     Reply With Quote
Old 08-22-2003, 05:19 AM   #3
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 239
Thanked: 2
man select_tut is a great place to start with the use of select ..and further..it contains sample code also..
so it will explain the stuff in great detail
shishir is offline     Reply With Quote
Old 08-22-2003, 10:41 AM   #4
Pres
Member
 
Registered: Jun 2002
Location: Australia
Distribution: Slack 9.1
Posts: 232
Thanked: 0

Original Poster
Thanks fellas, I was a little bit distraught about this but as it turns out things are under control. Situation was nothing at all to do with select() but more to do with other buggy parts of code. Fixed now and against all expectations, all apparently working.
Pres is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sockets. Writing while select()ing? daryl_tt Programming 4 11-11-2005 01:48 PM
open/query remote udp sockets in shell macie Programming 2 03-20-2005 04:45 PM
C sockets Select call when to use? cranium2004 Programming 1 03-14-2005 06:56 AM
Sending files over udp sockets in C raszagal Programming 9 11-27-2004 12:49 PM
UDP and select() confusion Pres Programming 2 07-26-2003 01:18 AM


All times are GMT -5. The time now is 10:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration