Thread: Basic thread and socket question

  1. #1
    Registered User
    Join Date
    May 2012

    Basic thread and socket question


    TL;DR - Can I listen on a socket to check for when more data arrives from a server then set a variable to true to indicate that data has arrived?

    I have a server and I need to code a client to access it and process data. The client currently receives data from the server using read(..). Every x amount of seconds (where x is a random number), the server will send new data to the client.

    However, during this period of time where no data is being sent to the client, the client must be able to send data back to the server. After x seconds, the server will send new data, the client must stop accepting input from the user and the new data is printed. This bit has me stuck.

    I plan on creating a thread (I must use pthread) to handle input from the user, then destroy the thread as soon as more data from the server arrives. Am I able to listen to a socket to check for when more data has arrived?


  2. #2
    Registered User
    Join Date
    Jun 2005
    Look up non-blocking sockets and the select() function.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming and thread safety
    By cloudy in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-12-2010, 08:44 AM
  2. Listening socket and thread problem
    By esaptonor in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2010, 03:04 AM
  3. Basic socket programming
    By cnewbie1 in forum C Programming
    Replies: 1
    Last Post: 03-28-2010, 05:10 PM
  4. Asynchronous Socket Thread closes after first receive
    By AndreasS in forum C# Programming
    Replies: 1
    Last Post: 04-16-2009, 08:31 AM
  5. Replies: 6
    Last Post: 03-12-2008, 01:19 PM