Thread: Writing a linux server in C

  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    UK
    Posts
    2

    Question Writing a linux server in C

    Hi all

    If after some direction. I would like to write a server to run on debian using c and gcc.

    1. The server should talk to clients via tcp
    2. Read and write to the serial port (To control robot hardware and read sensors)
    3. Procces commands from the network and return data to client re robot state.

    All of these tasks should be non blocking for proccessed in parrallel.

    Should I use fork() to set up 3 proccesses, one for each service ?
    If I do this how should each proccess communicate ?

    I have had a look at Beej's network programming tutorial and have had a client and server running, Im just not sure on how to integrate the other functions needed.

    Any pointers to put me on the right course would be welcomed.

    Thanks
    Rob

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Look up the select() call.
    It allows you to monitor a number of file descriptors, and then act on each of them with something to do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    UK
    Posts
    2

    Thumbs up Thanks for the hint

    Im now playing with fcntl(socket, cmd, O_NONBLOCK);

    This seems to be working. I just need a play with select and I should be some where near a running framework.

    I currently have :
    Code:
    start_server();
    launch_network_listnener();
    set_network_to_non_blocking();
    while(1)
    {
           Check_for_net_connection();
           Answer_connection_in_fork();
           any_thing_else_i_need();
    }
    Thanks very much for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TCP Server cannot save buffer data to mysql !
    By syedmuhd in forum C Programming
    Replies: 5
    Last Post: 09-18-2010, 08:54 PM
  2. INT 15 to return memory size
    By pole1080 in forum C Programming
    Replies: 49
    Last Post: 06-23-2010, 09:28 AM
  3. Writing a linux hardware driver
    By nexusone in forum Linux Programming
    Replies: 1
    Last Post: 08-12-2008, 07:33 PM
  4. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  5. Server Architecture
    By coder8137 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-29-2008, 11:21 PM