コード例 #1
0
ファイル: pserver-basic.c プロジェクト: angelachan64/Notes
int main() {

  int to_client;
  int from_client;
  char buffer[100];
  
  to_client = server_handshake( &from_client );
  
  while( 1 ) {
    printf("<server> waiting for connection\n");
    to_client = server_handshake( &from_client );
    
    while( read( from_client, buffer, sizeof(buffer) ) ){ // The end of file character would be when it reads 0 bytes
      printf( "<server> received [%s]\n", buffer );
      strncat( buffer, "purple monkey dishwasher", sizeof(buffer)-1 ); // THIS IS WHERE YOU WOULD PROCESS THE INPUT
      write( to_client, buffer, sizeof(buffer) );

      strncpy( buffer, "", sizeof(buffer) );
    } 
  
  close( to_client );

  }
}
コード例 #2
0
ファイル: server-forking.c プロジェクト: timothyong/systems
int main(){
  signal(SIGINT, signalhandler);
  char buffer[256];
  while(1){
    assert(mkfifo("mario", 0644) == 0);
    int from_client = open("mario", O_RDONLY);
    int to_client = server_handshake(from_client);
    int f = fork();
    if (f == 0){
      while(read(from_client, buffer, 256)){
	change_case(buffer);
	write(to_client, buffer, strlen(buffer) + 1);
      }
      exit(0);
    }
  }
}
コード例 #3
0
ファイル: pserver_basic.c プロジェクト: hrxiao/SysLev
int main() {

    int to_client;
    int from_client;
    //char buffer[100];

    while (1) {
        printf("<server> waiting for connection\n");
        to_client = server_handshake( &from_client );

        client_connection( to_client, from_client );

        close( to_client );
    }

    return 0;
}
コード例 #4
0
ファイル: p1.c プロジェクト: jerrylei98/C-Hangman
int main(){
  int to_client;
  int from_client;
  char buffer[100];

  while(1){
    printf("<server> waiting for connection\n");
    to_client = server_handshake(&from_client);
    
    while(read(from_client, buffer, sizeof(buffer))){
      printf("<server> received [%s]\n", buffer);
      //      process(buffer);
      write(to_client, buffer, sizeof(buffer));
      strncpy(buffer,"", sizeof(buffer));
      close(to_client);
    }
  }
  return 0;
}
コード例 #5
0
ファイル: fserver.c プロジェクト: hrxiao/SysLev
int main() {
	signal(SIGINT,sighandler);

	while (1) {
		int to_client = 0;
		int from_client;
		char buffer[100];

		while (!to_client)
			to_client = server_handshake(&from_client); //returns downstream pipe descriptor

		while (read(from_client, buffer, sizeof(buffer))) {

			printf("Mirror subserver [%d] received [%s]\n", getpid(), buffer);
			process(buffer);
			write(to_client, buffer, sizeof(buffer));
			strncpy(buffer,"",sizeof(buffer)); //refreshes buffer
		}
	}
	return 0;
}
コード例 #6
0
ファイル: server.c プロジェクト: angelachan64/final
int main(){
  
  signal( SIGINT, sighandler );

  int to_client;
  int from_client;
  char buffer[200];
  int elder;
  char SPLIT[3] = "\n";
  //char SPLIT[18] = "010203040506070809";
  char parts[100];
  char message[200] = "";
  while (1){
    to_client = server_handshake( &from_client );
    
    elder = fork();
    //printf("Elder Number is: %d\n", elder);
    if (elder == 0){ // i.e. child
      while (1){
	memset(buffer,0,strlen(buffer));
	int stop = read( from_client, buffer, sizeof(buffer));
	if (stop<=3){
	  exit(0);
	}
	printf("Words sent from sub: %s\n", buffer);
	//printf( "<Server> received: %s\n", buffer);

	int fd = open( name, O_CREAT | O_WRONLY | O_TRUNC, 0644);

	//change the semaphore and or shared memory
	if (fd<0){
	  printf("Problem: %s\n", strerror(errno) );
	} else {
	  write( fd, buffer, sizeof(buffer) );
	}
	close(fd);

	int i = 0;
	while (buffer[i]){
	  if (buffer[i] == '\n'){
	    break;
	  }
	  i++;
	}
	strncpy(message, buffer, i);
	
	
	//printf("Name: %s\n", message);
	//#####################################################
	//sends this to the MS.
	//changes a semaphore
	//MS checks semaphores or shared memory, reverts it back to normal
	//MS then reads it.
	//MS sends back a response and changes semaphore
	//strcat(message, parts);
	//parts = strsep(&buffer, SPLIT); //to_who
	//strcat(message, parts);
	//parts = strsep(&buffer, SPLIT); //message
	//strcat(message, parts);
	
	/*
	
	while (buffer[i]){
	  ch = toupper(buffer[i]);
	  buffer[i] = ch;
	  i++;
	}
	buffer[i]= '?';
	buffer[i+1] = 0;
	*/

	write( to_client, message, sizeof(message));
      }
    } //if (i == 0)
    else{ //parent
      close (to_client);
      close (from_client);
      scanThrough();
      /*
      while (a<num_at){
	printf("Names: %s\n", names[a]);
	a++;
      }
      */
    }

  }

}