Thread: program structure with select sockets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I understand your problem, but you need to understand, that Microsoft didn't create socket programming, it's just the same.
    I believe the guide contains a section explaining how to make the functions to work under windows, please read it!

    But any way, the examples work, trust me on that one, the only thing that could be a problem for windows is fork() which is nothing more than a new child process "creator", but is not supported by windows.


    As for a command line program, I can't believe you did API before simple command like applications.

    Just remember to keep looping, set a timeout timer for select and avoid getting to the blocking functions, unless you have incoming data which will not make the functions to block. And each time select timeouts display a message.
    Go through the example again; As far as I remember it works on windows.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    This was an example of the implementation of select() in Beej's code;

    Code:
    /*
    ** select.c -- a select() demo
    */
    
    #include <stdio.h>
    #include <sys/time.h>
    #include <sys/types.h>
    #include <unistd.h>
    
    #define STDIN 0  // file descriptor for standard input
    
    int main(void)
    {
        struct timeval tv;
        fd_set readfds;
    
        tv.tv_sec = 2;
        tv.tv_usec = 500000;
    
        FD_ZERO(&readfds);
        FD_SET(STDIN, &readfds);
    
        // don't care about writefds and exceptfds:
        select(STDIN+1, &readfds, NULL, NULL, &tv);
    
        if (FD_ISSET(STDIN, &readfds))
            printf("A key was pressed!\n");
        else
            printf("Timed out.\n");
    
        return 0;
    }
    I don't like to copy code, so i tried to write my own code from looking at that, but it didn't work, so i tried copying the code, and that didn't work either, my compiler doesn't recognize any of the "FD" commands. this is all the code, and it was linked to w2_32.lib.

    Edit: because it seems that those FD commands are all over his code, i got discouraged and gave up on his tutorial.
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Simple Structure program
    By dopejack in forum C Programming
    Replies: 19
    Last Post: 12-15-2007, 10:30 AM
  3. Sockets program
    By athos in forum Networking/Device Communication
    Replies: 5
    Last Post: 08-14-2004, 02:46 PM
  4. Simple program structure.
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 05-15-2002, 04:36 AM
  5. structure program
    By prlove71 in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2002, 09:01 PM