Esempio n. 1
0
void test_upt() {
    OekMsg msgs[2];
    msgs[0] = _get_stacmd();
    msgs[1] = NULL;
    send_to_server(msgs);

    assert(!read_from_server("\"start\""));

    msgs[2];
    msgs[0] = _get_uptcmd();
    send_to_server(msgs);

    assert(read_from_server("err") == 0);
}
Esempio n. 2
0
/*-----------------------------------------------------------------------------------------------------------
 *
 * FUNCTION:                read_file_name
 *
 * PROGRAMMER/DESIGNER:     Martin Minkov
 *
 * INTERFACE:               void read_file_name(int msg_id, msgbuf* msg)
 *                              int msg_id:     The ID of the message queue
 *                              msgbuf* msg:    The data structure used to hold all user data. 
 *
 * RETURNS:                 void
 *
 * NOTES:                   Continuously prompts the user to enter a file name. Once entered, the function
 *                          stores the data in a buffer and sets the information needed for the messsage
 *                          data structure. The msg_data field is used with a [PID] [FILENAME] format.
 *                          After sending the data via a message queue, the function sets the local
 *                          PID to the message type and starts to listen for data from the server.
 *
 * ---------------------------------------------------------------------------------------------------------*/
void read_file_name(int msg_id, msgbuf* msg)
{
	char filename[BUFFERLENGTH];
	int pid;
    pthread_t user_thread;

	pid = getpid();

	while (1)
	{
        pthread_create(&user_thread, NULL, (void *)print_thread, NULL);
		scanf("%31s", filename);
		msg->msg_type = 1;

		//Set msgbuf info 
		sprintf(msg->msg_data, "%d", pid);
		strcat(msg->msg_data, " ");
		strcat(msg->msg_data, filename);
		msg->msg_done = 0;
		msg->msg_len = MESGHDRSIZE;

        //Send message
		if (send_message(msg_id, msg) == -1)
		{
			fatal("Send message");
		}

		//Assign PID to msg
		msg->msg_type = (long) pid;
		read_from_server(msg_id, msg->msg_type);

		memset(msg->msg_data, 0, sizeof(msg->msg_data));
		memset(filename, 0, sizeof(filename));
	}
}
Esempio n. 3
0
int do_rawBPP(vnc_client *c, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
	uint32_t len = w * h * BYTES_PER_PIXEL;
	PIXEL *pixels = (PIXEL*) malloc(len);
	int ret = read_from_server(c, pixels, len);
	if(ret < 0)
	{
		free(pixels);
		return -1;
	}

	int i = 0;
	int j = 0;
	int fb_index = x + y * c->width;
	int pix_index = 0;

	PIXEL *fb = (PIXEL*) c->framebuffer;

	for(; i < h; i++)
	{
		j = 0;
		for(; j < w; j++)
		{
			#if BPP == 32
				pixels[pix_index + j] |= (0xff << 24); // set alpha
			#endif
			fb[fb_index + j] = pixels[pix_index + j];
		}
		fb_index += c->width;
		pix_index += w;
	}
	free(pixels);

	return 0;
}
Esempio n. 4
0
void test_upl() {
    OekMsg msgs[2];
    msgs[0] = _get_uplcmd();
    msgs[1] = NULL;
    send_to_server(msgs);

    assert(!read_from_server("lease not found"));
}
Esempio n. 5
0
void test_take() {
    OekMsg msgs[2];
    msgs[0] = _get_getcmd(true, (oe_scalar) "one", (oe_scalar) "two");
    msgs[1] = NULL;
    send_to_server(msgs);

    assert(!read_from_server("\"get\""));
}
Esempio n. 6
0
void test_unconnected_put() {
    OekMsg msgs[2];
    msgs[0] = _get_putcmd((oe_scalar) "one", (oe_scalar) "two");
    msgs[1] = NULL;
    send_to_server(msgs);

    //assert(!read_from_server("err:"));
    read_from_server("err:");
}
Esempio n. 7
0
void test_con() {
    OekMsg msgs[4];
    msgs[0] = _get_concmd();
    //msgs[1] = _get_concmd(); //cause error by double connect
    msgs[1] = NULL;
    msgs[2] = NULL;
    send_to_server(msgs);
    assert(!read_from_server("\"connect\""));
}
Esempio n. 8
0
void test_con_2() {
    OekMsg msgs[4];
    msgs[0] = _get_concmd();
    msgs[1] = NULL;
    msgs[2] = NULL;
    send_to_server(msgs);
    //assert(!read_from_server("err:"));
    read_from_server("err:");
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
  if(argc < 2 || argc > 4)
  {
    printf("\n Usage: %s port [a|b] [name] \n",argv[0]);
    return 1;
  } 
  sockfd = server_connect(argv[1]);
  if (sockfd < 0) {
    // something happened while trying to connect-- abort mission
    return -1;
  }
  
  parse_settings(argv[2], argv[3]);


  printf("Request name %s and team %d\n", name, team);

  //construct proper sendBuff
  //(name, team)
  snprintf(sendBuff, sizeof sendBuff, "%s %d", name, team);

  // send it
  send_to_server();
  // read reply
  read_from_server();

  //printf("Bytes written: %d. Bytes read: %d.\n%s\n", writtenbytes, readbytes, recvBuff);
  sscanf(recvBuff, "%s", recvName);
  printf("%s\n", recvBuff);
  char *ghs = "Game has already started";
  if(strcmp(ghs, recvBuff) == 0){
    close(sockfd);
    return 0;
  }

  initscr();
  loading_screen();
  display_teams();
  start_color();
  initscr();
  loadMap(mapNameFromServer);
  teamInfoMap();
  initBoard();/* creates play board */
  refresh();/* Print it on to the real screen */
  load_players();
  //place_players();
  control_test();
  final_standings();
  getch();
  endwin();

  close(sockfd);
  return 0;
}
Esempio n. 10
0
int do_copyrectBPP(vnc_client *c, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
	uint16_t copy_x = 0;
	uint16_t copy_y = 0;
	if(read_from_server(c, &copy_x, 2) < 0) { return -1; }
	if(read_from_server(c, &copy_y, 2) < 0) { return -1; }
	copy_x = sceNetNtohs(copy_x);
	copy_y = sceNetNtohs(copy_y);

	uint32_t src_idx = x + y * c->width;
	uint32_t dst_idx = copy_x + copy_y * c->width;
	
	int i = 0;
	for(; i < h; i++)
	{
		memcpy(((PIXEL*)c->framebuffer) + dst_idx, ((PIXEL*)c->framebuffer) + src_idx, w * BYTES_PER_PIXEL);
		src_idx += c->width;
		dst_idx += c->width;
	}
	return 0;
}
Esempio n. 11
0
void loading_screen(){
  int stop_loading_screen = 1;
  mvprintw(0, 0, recvName);//printing name revieved from server after balancing names
  mvprintw(1, 0, "Count Down:");

  while(stop_loading_screen){
    char gisFromServer[1024];
    char* gameStart = "GameIsStarting!";
    if(read_from_server() != 0){
      sscanf(recvBuff, "%s %s %s %s", gisFromServer, mapNameFromServer, a_team, b_team);
      mvprintw(1, 12, recvBuff);
      if (strcmp(gisFromServer, gameStart) == 0) {
        stop_loading_screen = 0;
      }
     }
    refresh();/* Print it on to the real screen */
  }
  clear();
}
Esempio n. 12
0
File: client.c Progetto: raphi011/os
/**
 * @brief Program entry point
 * @param argc The argument counter
 * @param argv The argument vector
 * @return EXIT_SUCCESS on success, EXIT_PARITY_ERROR in case of an parity
 * error, EXIT_GAME_LOST in case client needed to many guesses,
 * EXIT_MULTIPLE_ERRORS in case multiple errors occured in one round
 */
int main(int argc, char *argv[])
{
    char *server_arg;
    char *port_arg;
    struct addrinfo hints, *serv;
    int sockfd;
    int error;
    int ret = 0;


    if (argc > 0) {
        progname = argv[0];
    }
    
    if (argc < 3) {
        bail_out(EXIT_FAILURE, "Usage: %s <server-hostname> <server-port>", progname);
    }

    server_arg = argv[1];
    port_arg = argv[2];

     
    memset(&hints, 0, sizeof hints); 
    hints.ai_family = AF_INET; 
    hints.ai_socktype = SOCK_STREAM;
    error = getaddrinfo(server_arg, port_arg, &hints, &serv);
    
    if (error != 0) {
        bail_out(EXIT_FAILURE, "getaddrinfo error");
    }
    
    sockfd = socket(serv->ai_family, serv->ai_socktype, serv->ai_protocol);    
    
    if (sockfd < 0) {
        bail_out(EXIT_FAILURE, "socket error");
    } 

    /* Connect the socket to the address */
    if (connect(sockfd, serv->ai_addr, serv->ai_addrlen) != 0) {
        bail_out(EXIT_FAILURE, "connect error");
    }

    for (int round = 0; ; round++) {
        static uint8_t buffer;
        bool parity_error;
        bool game_lost;
        bool game_won;

        uint8_t color[2]; 
        
        next_guess(color);
    
        if (write(sockfd, &color, sizeof(color)) < 0) {
            bail_out(EXIT_FAILURE, "write error");
        }

        if (read_from_server(sockfd, &buffer, READ_BYTES) == NULL) {
            bail_out(EXIT_FAILURE, "read_from_server");
        }
        
        /* read status flags and evaluate if we've won */
        parity_error = buffer & (1 << PARITY_ERR_BIT);
        game_lost = buffer & (1 << GAME_LOST_ERR_BIT);
        game_won = (buffer & SLOTS) == SLOTS;

        if (parity_error) { 
            (void)fprintf(stderr, "Parity error");
            ret = EXIT_PARITY_ERROR;
        } 
        if (game_lost) {
            (void)fprintf(stderr, "Game lost"); 
            if (ret == EXIT_PARITY_ERROR) {
                ret = EXIT_MULTIPLE_ERRORS;
            } else {
                ret = EXIT_GAME_LOST; 
            }
        }   

        if (game_won) {
            (void)printf("Won after %d round(s)", round+1);
            break;
        } else if (ret) {
            break;
        }
    } 

    freeaddrinfo(serv);

    return ret;
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
    long portno;
    int i, con_count=1;
    time_t t1,t2,t3,t4;
    char wbuffer[256];
    int connlist[1024*65];
    int result[1024*65];
    struct hostent *server;
    struct sockaddr_in serv_addr;

    INIT();

    if (argc != 4) {
        fprintf(stderr,"Usage:\n\t%s hostname port clients\n\n", argv[0]);
        exit(0);
    }

    con_count = atol(argv[3]);
    if (con_count<1) con_count=1;
    if (con_count>1024*65) con_count=1024*65;

    portno = atol(argv[2]);
    if (portno<1l || portno>0xFFFFl) {
        fprintf(stderr, "ERROR, invalid port\n");
        exit(0);
    }

    server = gethostbyname(argv[1]);
    if (server == NULL) {
        fprintf(stderr, "ERROR, no such host\n");
        exit(0);
    }

    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    memcpy(server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons((short)portno);

    sprintf(wbuffer, "GET / HTTP/1.0\r\n\r\n");

    t1 = time(0);
    for (i=0;i<con_count;i++) {
        result[i] = connlist[i] = connect_to_server(&serv_addr);
    }
    t2 = time(0);
    for (i=0;i<con_count;i++) {
        if (result[i]>=0) {
            result[i] = send_to_server(connlist[i], wbuffer);
        }
    }
    t3 = time(0);
    for (i=0;i<con_count;i++) {
        if (result[i]>=0) {
            result[i] = read_from_server(connlist[i]);
        }
    }
    t4 = time(0);

    printf("\n");
    printf("conn:  %.0lf\n", difftime(t2,t1));
    printf("write: %.0lf\n", difftime(t3,t2));
    printf("read:  %.0lf\n", difftime(t4,t3));

    for (i=-10;i<1000;i++) {
        int j,cnt=0;
        for(j=0;j<con_count;j++) {
            if (result[j]==i) cnt++;
        }
        if (cnt>0) {
            printf("%5i\t%7u\n", i, cnt);
        }
    }

    return 0;
}