Thread: (urgent) Multiplayer Poker game using Socket Programming

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Whilst View Post
    i got a hint for the project today saying I need to have a receiving() function threaded so it will refresh things up everytime the program receives something. would that make sense?
    If you are using GTK and glib and you are talking about a socket, I would use g_io_add_watch() for this. You do not have to thread it. io_watch accepts a socket descriptor and a callback. You put it inside your gtk_main_loop and when there is data waiting to be read on the socket (ie, an incoming call) the callback function will be called. This is somewhat simpler and cleaner than a separate dedicated thread (altho it amounts to the same thing and I would imagine is implemented that way).

    Here's an additional tip: the third parameter to g_io_add_watch_full is a condition. You want G_IO_IN, that is, a normal incoming message. However, it is a good idea to set up a second watch on the same socket with G_IO_HUP, then set the priority of this watch (second parameter) HIGHER** than the IN watch. HUP will respond if the other end of the socket disconnects -- this is an error situation*. Otherwise, if the connection goes bad, you will get an undesirable event on the IN watch (this will be true for a normal socket setup too, except AFAICT the normal socket API does not allow you to detect HUP, so you are stuck with the "undesirable event", which is a non-stop flood of recv's with no content).

    * probably the end of the program unless you set up a means of reconnecting.
    ** lower number = higher priority
    Last edited by MK27; 10-20-2009 at 09:51 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a Poker Game
    By krazyxazn in forum C Programming
    Replies: 4
    Last Post: 04-07-2009, 06:45 PM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  3. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  4. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 07:58 PM
  5. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM