client-server problem

client-server problem

Post by Lorenz » Wed, 20 Feb 2002 06:44:07



Hello I have a little problem.
I have a server and a client, the client stops the server,then it waits for
5,and then it sends the signal SIGINT  to the server.
The server stops ( after client sends SIGSTOP) and then restarts ( after
client sends SIGCONT ) ,but after the server restarts and it doesn't execute
the switch and so it re-stops again ,but the client hasn't sends the SIGSTOP
signal.
Look at the source, first launch the server in bk and then launch the client
,and look the output.I have tried a lot of solutions but without
success.Where is the mistake?PLZ help me.
Thanks

Giuseppe

the source,but first you have to create a named file : chiave ,it is the key
for the ftok call.

server --------------------------------------------------------------

#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/shm.h>

#include <sys/sem.h>

#include <sys/stat.h>

#include <errno.h>

#include <sys/stat.h>

#include <sys/wait.h>

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <fcntl.h>

#include <signal.h>

#define SIZE 2

int shm_id,shm_id_lista;

int

main(void)

{

pid_t *process;

key_t mykey,mykey_lista,mykey_sem_bin;

pid_t pid_agenzia;

char scelta[SIZE];

int numero_sel;

int num;

mykey = ftok("./chiave",'a');

if ( mykey == - 1 )

{

perror("ERRORE - FTOK NON HA GENERATO LA CHIAVE PER IL PID ");

exit(1);

Quote:}

shm_id = shmget(mykey,sizeof(pid_t),IPC_CREAT | SHM_R | SHM_W);

if (shm_id == -1)

{

perror("ERRORE - MEMORIA CONDIVISA NON CREATA ");

exit(1);

Quote:}

process=(int *)shmat(shm_id,0,0);

if ((int)process == -1)

{

perror("ERRORE - MEMORIA CONDIVISA NON COLLEGATA ");

exit(1);

Quote:}

*process = getpid();

write(1,"\n sono il server",16);

// raise(SIGSTOP);

sleep(10);

write(1,"\n server restarted\n",20);

/*write(1,"\nserver restarted",19);

*/

while (num != 4)

//do

{

write(1,"num=",4);

read(STDIN_FILENO,&num,1);

// numero_sel = getc(stdin);

// scelta = getc(stdin);

// scanf("%c",&scelta);

//scelta = getchar();

switch(num)

{

case '0' :

printf("\n caso 0");

break;

case '1' :

printf("\n caso 1");

break;

case '2' :

printf("\n caso 2");

break;

case '3' :

printf("\n caso 3");

break;

Quote:}
}

// while (num == '1');

Quote:}

client ------------------------------------------------------------------

#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/shm.h>

#include <sys/sem.h>

#include <sys/stat.h>

#include <errno.h>

#include <sys/stat.h>

#include <sys/wait.h>

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <fcntl.h>

#include <signal.h>

int shm_id,shm_id_lista;

int

main(void)

{

pid_t *process;

key_t mykey,mykey_lista,mykey_sem_bin;

pid_t pid_agenzia,pid_server;

mykey = ftok("./chiave",'a');

if ( mykey == - 1 )

{

perror("ERRORE - FTOK NON HA GENERATO LA CHIAVE PER IL PID ");

exit(1);

Quote:}

shm_id = shmget(mykey,sizeof(pid_t),IPC_CREAT | SHM_R | SHM_W);

if (shm_id == -1)

{

perror("ERRORE - MEMORIA CONDIVISA NON CREATA ");

exit(1);

Quote:}

process=(int *)shmat(shm_id,0,0);

if ((int)process == -1)

{

perror("ERRORE - MEMORIA CONDIVISA NON COLLEGATA ");

exit(1);

Quote:}

pid_server = *process;

kill(pid_server,SIGSTOP);

sleep(5);

//pid_server = *process;

kill(pid_server,SIGCONT);

Quote:}

 
 
 

1. Client-Server , problem using send(socket,...) command .

Hi .

  - I'm working on sparc-5 , solaris2.5 system .
  - I wrote a client-server application using tcp/ip sockets .(
CONNECTION_STREAM )
  - I need to send data from the client to the server using  send(..)
command .

  The problem :
  If  I    d o n ' t   use delay time between send to shutdown commands
in the client application ,
  the server application doesn't get nothing .

  for example , in the client application : using that code , cause the
server to get nothing :

   send ( socket , .... ) ;
   shutdown ( socket , 2 );

while using sleep between send and shutdown in the client application  ,
server gets the data :
   send ( socket , .... )

   sleep(1)

   shutdown ( socket , 2 );

Maybe someone had this problem before and can help me ?
A n y   help will be appreciate .

Please replay to :

  vcard.vcf
< 1K Download

2. AIX and Digital UNIX

3. bind ports

4. Client-Server,Problem using send(socket,..) command .

5. Apache, ASP and VBScript

6. Client-server problem

7. problem referencing <linux/*.h> files

8. client-server problem

9. a client-server problem

10. NIS+: Client/Server problems. Design flaw?

11. Strange: Telnet client won't quit in a client-server application

12. Connecting two machines:; Client only communicate with server when server continuously pings client.