コード例 #1
0
ファイル: ctcp_sys_internal.c プロジェクト: chuzui/courses
/**
 * Start a client.
 *
 * server: String containing the server to connect to.
 * port: The port the client will run on.
 */
int start_client(char *server, char *port) {
  if (do_config_server(server) < 0 || do_config(port) < 0)
    return -1;

  /* Initialize connection with server. Go to student code. */
  conn_t *conn = tcp_handshake();
  ctcp_config_t *config_copy = calloc(sizeof(ctcp_config_t), 1);
  memcpy(config_copy, ctcp_cfg, sizeof(ctcp_config_t));
  ctcp_state_t *state = ctcp_init(conn, config_copy);
  if (state == NULL) {
    fprintf(stderr, "[ERROR] Could not connect to server!\n");
    return -1;
  }
  fprintf(stderr, "[INFO] Connected to server\n");
  config->sconn->state = state;

  setup_poll();
  do_loop();
  return 0;
}
コード例 #2
0
ファイル: sender_main.c プロジェクト: thibautx/mp3
void init(char* hostUDPport, char* hostname){
	setup_network(hostUDPport, hostname);
	tcp_handshake();
	start_machine(); // set Start state
	sequencenumber = 1;
}