Threads communcation in network programming

Discussion in 'C Programming' started by QQ, May 8, 2005.

  1. QQ

    QQ Guest

    Hello I am a beginner for network programming.
    Now I am trying to implement some function like this

    I am keep listening to a port, when I get some message, I will have
    some corresponding response. And the same time, I can send out message.

    So I put the listening function in the child process.
    My question is when I receive some packet, how can I send signal to the
    main thread.
    Thanks a lot!
    QQ, May 8, 2005
    #1
    1. Advertising

  2. QQ

    Malcolm Guest

    "QQ" <> wrote in message
    >
    > I am keep listening to a port, when I get some message, I will have
    > some corresponding response. And the same time, I can send out message.
    >
    > So I put the listening function in the child process.
    > My question is when I receive some packet, how can I send signal to the
    > main thread.
    >

    You go beyond ANSI C, because there is no signalling / interrupt mechanism.
    These are often provided as platform-specific calls.

    However ANSI C does provide "volatile". This flags a variable as being able
    to be altered by an outsode process, such as your child.

    So a simple scheme would be

    global variables:

    struct packet data;
    volatile int semaphore;

    /* child */

    wait till packet comes.
    if semaphore not "clear" you have a problem. Maybe busy idle checking it
    until it goes to "clear".
    set semaphore to busy.
    write data to global structure
    set semaphore to "data ready"
    wait till next packet comes.

    /* main process */
    every so often, check semaphore.
    if it is set to "data ready" set semaphore to "busy", other wise go back to
    main loop
    read data into own structure
    set semaphore to clear.
    go back to main loop.
    Malcolm, May 8, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kal
    Replies:
    1
    Views:
    9,502
    Kevin Spencer
    Jun 21, 2004
  2. Jane Davis

    Network Service account over network

    Jane Davis, Jun 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    425
    Kevin Spencer
    Jun 22, 2005
  3. Bill Volk
    Replies:
    1
    Views:
    3,129
    Bill Volk
    Jul 2, 2003
  4. kin
    Replies:
    0
    Views:
    908
  5. king
    Replies:
    1
    Views:
    265
Loading...

Share This Page