Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
72 user(s) are online (52 user(s) are browsing Forums)

Members: 1
Guests: 71

DanN, more...

Support us!

Headlines

 
  Register To Post  

Listen on scoket and for other signals (like CTRL-C)
Just popping in
Just popping in


See User information
Hi,

does anyone know how to listen on a server socket (ISocket-listen) and on the same time listen for other signals like CTRL-C.

I'm looking for something like ISocket->WaitSelect but for a server implementation.

regards

max

Go to top
Re: Listen on scoket and for other signals (like CTRL-C)
Just popping in
Just popping in


See User information
@MigthyMax

I figured it out by myself. If somebody wants to know how to do it. You can actually use ISocket->WaitSelect for implemneting a simple server like this (simplified, no error checking etc):

ISocket->bindsocket,(struct sockaddr *)&addr,sizeof(addr) );
ISocket->listensocket,)

for( 
int loop TRUE;loop; ) {
  
fd_set listenFds;
  
FD_ZERO( &listenFds );
  
FD_SETsocket,&listenFds );

  
printf("Listening.....\n");
  
ULONG signals SIGBREAKF_CTRL_C;
  
int readyDescriptors ISocket->WaitSelectsocket +1,&listenFds,NULL,NULL,NULL,&signals );

  if( 
readyDescriptors == -) {
    
printf"Network Error.\n" );
    
loop FALSE;
  } 
  else {
    if( ( 
signals SIGBREAKF_CTRL_C ) == SIGBREAKF_CTRL_C ) {
      
printf"Detected CTRL-C.\n" );
      
loop FALSE;
    }

    if( 
FD_ISSETsocket,&listenFds ) ) {
      
int client ISocket->acceptsocket,NULL,NULL );
      if( 
client != -) {
        
printf("Client connected.\n"); 
        
ISocket->CloseSocketclient );
      }
    }
  }
}

Go to top
Re: Listen on scoket and for other signals (like CTRL-C)
Just can't stay away
Just can't stay away


See User information
thx for posting example/code

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 2 ( 0 members and 2 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project