Thread: Implementing a server without fork()

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    Implementing a server without fork()

    I have a school homework that asks me to create a chat server (tcp) without creating new processes.
    The problem is that the server has a console. i need to be able to send the server some input whenever i want... I need to use the select function for the mux of the i/o. the server waits on the select function and i'm not able to read from stdin

    how can i solve this ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Add stdin (ie, fd 0) to the FD_SET of descriptors you pass to select.

    Then you can wait for interesting things to happen on user input, as well as input from your sockets.
    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
    Dec 2005
    Posts
    167
    recv(0,(char*)cmd,sizeof(cmd),0);

    how can i receive interesting things from stdin... this doesn't work

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well I've no idea how to figure out what "it doesn't work" really means from such a terse problem report and one line of code.
    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.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    sorry... i was asking how do i read my input from stdin? do i use the recv function ?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use the read() function.
    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.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by spank View Post
    recv(0,(char*)cmd,sizeof(cmd),0);

    how can i receive interesting things from stdin... this doesn't work
    Don't use recv() on a file descriptor, use read().

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    great... thank you! i solved this

  9. #9
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by spank View Post
    great... thank you! i solved this
    In general, you can use read() instead of recv(), but you cannot use recv() instead of read(). read() will read anything, recv() can only read from sockets.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Server Architecture
    By coder8137 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-29-2008, 11:21 PM
  2. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  3. fork(), exit() - few questions!
    By s3t3c in forum C Programming
    Replies: 10
    Last Post: 11-30-2004, 06:58 AM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM