I had seen some posts at this forum talking about my problem, but maybe my scenario is a little different, and I want other solutions.
I saw users of this forums saying that the way to shared sockets is using UNIX Sockets, but this is the only way in my scenario?
My Scenario:
I have a process that is the server. Server accepts clients (sockets) and then call to fork. If two clients connects to my server, parent process will have two childs, and now is my problem, one of this child need to send a message to the another child.
First, I thinked that I could save fd socket in share memory, and then using this fd in another child I'll be able to send messages to another client, but doesn't works...
I had seen some posts at this forum talking about my problem, but maybe my scenario is a little different, and I want other solutions.
I saw users of this forums saying that the way to shared sockets is using UNIX Sockets, but this is the only way in my scenario?
My Scenario:
I have a process that is the server. Server accepts clients (sockets) and then call to fork. If two clients connects to my server, parent process will have two childs, and now is my problem, one of this child need to send a message to the another child.
First, I thinked that I could save fd socket in share memory, and then using this fd in another child I'll be able to send messages to another client, but doesn't works...
Any ideas?? Thanks!
PD: Sorry for my bad english
Hi,
you can use shared_memory IPC to share the sockets(any data) between the two processes via a unique key. Otherwise you can instead create threads when you serve a new request. Then you save the overhead of forking a new process.
Thanks,
Gaurav.
This User Gave Thanks to gaurav1086 For This Post:
Yes, I tried this, but not worked for me. How Can I shared a socket?
I tried to share value of " fd_client = accept(sock,0,0); ". I saved value of fd_client in a shared memory, but then when I read this value, and write into it, really I'm writting in the childs socket, and not in the value that I saved (another child).
Can you give me an example to share a socket with IPC? Thanks!
Hi!!
No, because I did a lot of changes these days... for example, now I'm trying to do with pipes, but I can describe.
I create a struct, and then I shared with shared memory, struct was this:
And struct and shared memory works good (tested).
My server is listening connections, when connection arrives then forks and the client go to child. Before fork, I saved value of "fd_client = accept(sock,0,0);" into struct client[0]->fd=fd_client;
Then, when another children needs to write in the socket of another child, I search in the struct the fd of the another child, because I know he's login. Then I call write(fd,"test",4);
Problem? word "test" is send to the actual child, and I can see in his screen the word "test", when I need to write this "test" in the screen of the other child.
Now, seeing this, maybe I need to save value of "sock" instead "fd_client"??
Hey guys,
I have to make a C program that simulates this command :
cat (files here) | sort > file.txt
So, I start and create a pipe. Then create the first child. This first child will execute the Cat through the pipe. Then create a second child that will execute sort, with input from... (4 Replies)
I need clarification on whether it is okay to set socket options on a listening socket
simultaneously when it is being used in an accept() call?
Following is the scenario:-
-- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Hi gurus, I would like to fork more children and then write their return values: so far I tried:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void)
{
pid_t pid;
int rv=0, i;
... (5 Replies)
Hello every one i am implementing client server program.To handle multiple fds of client in server i used poll function.But this poll not able to access socket fd from other process.How can i share socket fd between two process.
Please Help me,Thanks in advance. (3 Replies)
Hello every one i am implementing client server program.To handle multiple fds of client in server i used poll function.But this poll not able to access socket fd from other process.How can i share socket fd between two process.
Please Help me,Thanks in advance. (1 Reply)
Hi all,
I m writing an application, where i need to fork multiple childs and those child should handle particular task given to them.
More descriptive.
For example, suppose i have 4 Network, each network has multiple nodes. Now on the basis of network child should be forked and these child... (8 Replies)
Hi,
I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime.
To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
hi, i want to write a code for forking 3 4 child. n wants that every child process one of the account from global account list. i wrote a program for that, but problem is every child is processing every account in list. what can me done to avoid it.
attaching code with it
#include <stdio.h>... (2 Replies)
I need to write a shell script which would take 2 arguments pid , userid. Then it should kill all the child process under it. If a child process is not killed then it should wait for 1 minute and should kill.
can anybody give me the idea to write it? (0 Replies)