LinuxQuestions.org
Visit Jeremy's Blog.
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
 
LinkBack Search this Thread
Old 08-21-2003, 10:43 AM   #1
Pres
Member
 
Registered: Jun 2002
Location: Australia
Distribution: Slack 9.1
Posts: 232

Rep: Reputation: 30
sockets, UDP, using select()


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.
 
Old 08-21-2003, 01:26 PM   #2
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
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 01:28 PM.
 
Old 08-22-2003, 04:19 AM   #3
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
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
 
Old 08-22-2003, 09:41 AM   #4
Pres
Member
 
Registered: Jun 2002
Location: Australia
Distribution: Slack 9.1
Posts: 232

Original Poster
Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 10:56 AM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration