Re: advices on sockets



Thank you very much for your answer.


Yes.  You could write it as a subroutine in your program, and use fork()
to start a new process.  In the new process you would call this
subroutine, while the original process would go back to trying to
connect.

ok but wouldn't the child process (the x-window/server) die when the
parent (graphics app/client) process dies too ?
That was my understanding of fork() behavior.

You might also want to arrange some additional communication between the
parent and child process, so that the child can tell the parent when it
has started the server.  Otherwise, if the parent tries to connect too
soon, it might think it needs to start the server again.  You could use
a semaphore for this.

hum i never studied semaphore ;-( but will have a look.

You need to use select() to listen for activity on multiple sockets at
once.  Or you can use threads, where one thread waits for new
connections, and other threads process existing connections.  If you
only expect a small number of clients this can be an easier way to
program it.

but isn't select() a blocking call too if the socket is non-blocking ?
I tried that approach as a matter of fact and did a call to select
within the loop that check for x-events as well... something like
that:

while(1) {
checkForXevents(&c);
if (c=='q')
break;
// hangs there... wait for something to happen ?
select(fdmax+1...);
}

if I don't make the socket non-blocking the loop hangs on select. If I
make it non-blocking and set a timeout value, you need to wait for a
timeout before the loop continues anyway... which is not so cool when
you want no delay in the user interaction with the window (keyboard,
mouse...). I looked at this problem on different angle and really
can't seem to figure it out. Maybe threading as you said would be an
option but that means a thread to catch x-events and treat them, and
other threads to catch new connections and read from those
connections.

When you say using thread are you thinking of pthread or fork ?

I guess what I could do would be the following:

1/ open the display
2/ create a thread to catch x-event and manipulate the framebuffer
accordingly (zoom in...)
3/ create a thread that "accept" new connections
4/ each connection starts a thread that listen to what's coming in on
that connection

It would be ok but I was hoping for something simpler... I don't want
that x-window/server app to use too much memory and CPU cycles to
leave as much processing power for the graphics app...

Thanks for more of your feedbacks/ideas if you have some

-c

.



Relevant Pages

  • Re: Correct table structure for people/children
    ... In addition to a FamilyID, each record in the People table needs the ... ways, for the purposes of generational and marriage connections, we ... determine who is the parent and who the child. ...
    (comp.databases.filemaker)
  • Re: advices on sockets
    ... child processes are not dependent on the parent. ... connections, and other threads process existing connections. ... if I don't make the socket non-blocking the loop hangs on select. ...
    (comp.unix.programmer)
  • Re: Some really confusing things about parent-child relationship
    ... In hierarchical model parent class can have several subclasses. ... instances of certain subclass, or that an instance A can have ... The last as in "an instance A can have connections to two or more ...
    (comp.databases.theory)
  • Some really confusing things about parent-child relationship
    ... In hierarchical model parent class can have several subclasses. ... That an instance A of parent class can have connections to several ... My book only briefly talks about network model, ...
    (comp.databases.theory)
  • Help Needed Java NIO server and Tomcat 100% CPU utilization !!!!
    ... I have a Async Server (listening for socket connections on one port) ... in a for loop which was not ending But to my dismay the problem ... got zero selected keys (after a threshold i.e after continues 50 zero ... This worked fine on my local machine as well as ...
    (comp.lang.java.programmer)