Basic thread and socket question

This is a discussion on Basic thread and socket question within the C Programming forums, part of the General Programming Boards category; Hello, TL;DR - Can I listen on a socket to check for when more data arrives from a server then ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    4

    Basic thread and socket question

    Hello,

    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?

    Problem
    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?

    Thanks

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

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21