sockets in linux question

This is a discussion on sockets in linux question within the Networking/Device Communication forums, part of the General Programming Boards category; hi im writing a multiple client - server socket using fork , i was wondering is there a way for ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    sockets in linux question

    hi im writing a multiple client - server socket using fork , i was wondering is there a way for the server to respond to all clients at the same time?
    im doing this socket for school i need that when the correct message is sent by one client the server respond the success to all clients and not only the one who send it. Can u point to the right direction to do this plz? thnx

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    Without broadcasting to the entire network it's probably best to just loop through all the connected sockets and send them the success message.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User Rennor's Avatar
    Join Date
    Aug 2006
    Location
    Finland
    Posts
    45
    You could share piece of memory with all of your forked child processes.

    Find more about "Shared Memory Functions" (shm.h) or about IPC facilities.

    You will be able to access same memory from unrelated processes.

    Functions to do this are:
    shmat(), shmctl(), shmdt() and shmget()

    The idea is to create the shared memory (shmget) and then attach to it (shmat). shmdt is for detaching and shmctl is control functions.

    So, you make structure with variables/data you want to share with processes, allocate/initialize it in your main application, create shared memory pointing to it, attach to it... Then you attach to same shared memory in each forked process and read it. Main program writes to variable like "send_to_client" value 1. Processes are checking if this variable is 1, if true, send socket stuff to client. Voila

    You can also have all kinds of other shared data in same shared memory. Only machine free memory is the limit to how much memory you can share.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    re

    How do i broadcast to the entire network?

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    Quote Originally Posted by itsme86
    Without broadcasting to the entire network it's probably best to just loop through all the connected sockets and send them the success message.
    Broadcast is LAN only and wouldn't reach clients outside the local subnet, and would also require using a stateless protocol (UDP probably) which isn't guaranteed to reach it's destination.

    Also, looping threw I'm not sure about, because the processes are forked they have their own memory space and don't know about any of the other sockets, so like it was said shared memory would probably be the better route.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    Quote Originally Posted by Xipher
    Broadcast is LAN only and wouldn't reach clients outside the local subnet, and would also require using a stateless protocol (UDP probably) which isn't guaranteed to reach it's destination.

    Also, looping threw I'm not sure about, because the processes are forked they have their own memory space and don't know about any of the other sockets, so like it was said shared memory would probably be the better route.
    1) He's doing it for school. It's probably on a LAN.
    2) Protocol wasn't specified.
    3) Even though it's forked, I'm sure the controlling process knows about all the connected clients.
    4) Do you just pull ........ out of your ass?
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thinking of upgrading to linux...
    By Yarin in forum General Discussions
    Replies: 37
    Last Post: 07-24-2009, 11:40 AM
  2. Linux (not programming) E-mail server question.
    By Kennedy in forum Tech Board
    Replies: 4
    Last Post: 11-09-2006, 01:08 AM
  3. question about asynchronous sockets
    By pode in forum Networking/Device Communication
    Replies: 8
    Last Post: 12-27-2004, 01:33 PM
  4. question from linux board ( not os dependant )
    By crypto in forum C Programming
    Replies: 4
    Last Post: 11-15-2002, 01:09 AM
  5. Question about LINUX
    By River21 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-17-2001, 06:39 PM

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