Exemple #1
0
int main() {
	//random seed for loss rate
	srand(time(NULL));
	//start overlay
	int overlay_conn = overlay_start();
	if(overlay_conn<0) {
		printf("fail to start overlay\n");
		exit(1);
	}

	//initialize srt client
	srt_client_init(overlay_conn);

	//create a srt client sock on port 87 and connect to srt server at port 88
	sock_t sockfd = srt_client_sock(87);
	if(!sockfd) {
		printf("fail to create srt client sock");
		exit(1);
	}
	if(srt_client_connect(sockfd,88)<0) {
		printf("fail to connect to srt server\n");
		exit(1);
	}
	printf("client connect to server, client port:87, server port 88\n");

	//create a srt client sock on port 89 and connect to srt server at port 90
	sock_t sockfd2 = srt_client_sock(89);
	if(!sockfd2) {
		printf("fail to create srt client sock");
		exit(1);
	}
	if(srt_client_connect(sockfd2,90)<0) {
		printf("fail to connect to srt server\n");
		exit(1);
	}
	printf("client connect to server, client port:89, server port 90\n");

	//wait for a while and close the connection to srt server
	sleep(5);
	if(srt_client_disconnect(sockfd)<0) {
		printf("fail to disconnect from srt server\n");
		exit(1);
	}
	if(srt_client_close(sockfd)<0) {
		printf("failt to close srt client\n");
		exit(1);
	}
	
	if(srt_client_disconnect(sockfd2)<0) {
		printf("fail to disconnect from srt server\n");
		exit(1);
	}
	if(srt_client_close(sockfd2)<0) {
		printf("failt to close srt client\n");
		exit(1);
	}
	//close overlay tcp connection
	overlay_stop(overlay_conn);
}
int main() {
	//random seed for loss rate
	srand(time(NULL));

	//start overlay and get the overlay TCP socket descriptor	
	int overlay_conn = overlay_start();
	if(overlay_conn<0) {
		printf("fail to start overlay\n");
		exit(1);
	}

	//initialize srt client
	srt_client_init(overlay_conn);

	//create a srt client sock on port CLIENTPORT1 and connect to srt server port SVRPORT1
	int sockfd = srt_client_sock(CLIENTPORT1);
	if(sockfd<0) {
		printf("fail to create srt client sock");
		exit(1);
	}
	if(srt_client_connect(sockfd,SVRPORT1)<0) {
		printf("fail to connect to srt server\n");
		exit(1);
	}
	printf("client connected to server, client port:%d, server port %d\n",CLIENTPORT1,SVRPORT1);
	
	//get sampletext.txt file length,
	//create a buffer and read the file data in
	FILE *f;
	f = fopen("send_this_text.txt","r");
	assert(f!=NULL);
	fseek(f,0,SEEK_END);
	int fileLen = ftell(f);
	fseek(f,0,SEEK_SET);
	char *buffer = (char*)malloc(fileLen);
	fread(buffer,fileLen,1,f);
	fclose(f);

	//send file length first, then send the whole file
	srt_client_send(sockfd,&fileLen,sizeof(int));
      	srt_client_send(sockfd, buffer, fileLen);
	free(buffer);

	//wait for a while and close the connections
	sleep(WAITTIME);

	if(srt_client_disconnect(sockfd)<0) {
		printf("fail to disconnect from srt server\n");
		exit(1);
	}
	if(srt_client_close(sockfd)<0) {
		printf("fail to close srt client\n");
		exit(1);
	}
	
	//stop the overlay
	overlay_stop(overlay_conn);
}
Exemple #3
0
int main() {
	//random seed for segment loss
	srand(time(NULL));

	//create a tcp connection to client
	int overlay_conn = overlay_start();
	if(overlay_conn<0) {
		printf("can not start overlay\n");
        perror("overloay_conn");
	}

	//initialize srt server
	srt_server_init(overlay_conn);

	/*one server*/	
	//create a srt server sock at port 88 
	int sockfd= srt_server_sock(88);
	if(sockfd<0) {
		printf("can't create srt server\n");
		exit(1);
	}
	//listen and accept connection from a srt client 
	srt_server_accept(sockfd);

	/*another server*/
	//create a srt server sock at port 90 
	int sockfd2= srt_server_sock(90);
	if(sockfd2<0) {
		printf("can't create srt server\n");
		exit(1);
	}
	//listen and accept connection from a srt client 
	srt_server_accept(sockfd2);


	sleep(10);

	//close srt client 
	if(srt_server_close(sockfd)<0) {
		printf("can't destroy srt server\n");
		exit(1);
	}				
	if(srt_server_close(sockfd2)<0) {
		printf("can't destroy srt server\n");
		exit(1);
	}				

	//close tcp connection to the client
	overlay_stop(overlay_conn);
}
int main() {
	//random seed for segment loss
	srand(time(NULL));

	//start overlay and get the overlay TCP socket descriptor
	int overlay_conn = overlay_start();
	if(overlay_conn<0) {
		printf("can not start overlay\n");
	}

	//initialize srt server
	srt_server_init(overlay_conn);

	/*create a server sock */	
	//create a srt server sock at port SVRPORT1 
	int sockfd= srt_server_sock(SVRPORT1);
	if(sockfd<0) {
		printf("can't create srt server\n");
		exit(1);
	}
	//listen and accept connection from a srt client 
	srt_server_accept(sockfd);

	/*another server sock*/
	//create a srt server sock at port SVRPORT2
	int sockfd2= srt_server_sock(SVRPORT2);
	if(sockfd2<0) {
		printf("can't create srt server\n");
		exit(1);
	}
	//listen and accept connection from a srt client 
	srt_server_accept(sockfd2);


	sleep(WAITTIME);

	//close srt server 
	if(srt_server_close(sockfd)<0) {
		printf("can't destroy srt server\n");
		exit(1);
	}				
	if(srt_server_close(sockfd2)<0) {
		printf("can't destroy srt server\n");
		exit(1);
	}				

	//stop the overlay
	overlay_stop(overlay_conn);
}
int main() {
	//random seed for loss rate
	srand(time(NULL));

	//start overlay and get the overlay TCP socket descriptor	
	int overlay_conn = overlay_start();
	if(overlay_conn<0) {
		printf("fail to start overlay\n");
		exit(1);
	}

	//initialize srt client
	srt_client_init(overlay_conn);

	//create a srt client sock on port CLIENTPORT1 and connect to srt server port SVRPORT1
	int sockfd = srt_client_sock(CLIENTPORT1);
	if(sockfd<0) {
		printf("fail to create srt client sock");
		exit(1);
	}
	if(srt_client_connect(sockfd,SVRPORT1)<0) {
		printf("fail to connect to srt server\n");
		exit(1);
	}
	printf("client connected to server, client port:%d, server port %d\n",CLIENTPORT1,SVRPORT1);
	
	//create a srt client sock on port CLIENTPORT2 and connect to srt server port SVRPORT2
	int sockfd2 = srt_client_sock(CLIENTPORT2);
	if(sockfd2<0) {
		printf("fail to create srt client sock");
		exit(1);
	}
	if(srt_client_connect(sockfd2,SVRPORT2)<0) {
		printf("fail to connect to srt server\n");
		exit(1);
	}
	printf("client connected to server, client port:%d, server port %d\n",CLIENTPORT2, SVRPORT2);

	//send strings through the first connection
      	char mydata[6] = "hello";
	int i;
	for(i=0;i<5;i++){
      		srt_client_send(sockfd, mydata, 6);
		printf("send string:%s to connection 1\n",mydata);	
      	}
	//send strings through the second connection
      	char mydata2[7] = "byebye";
	for(i=0;i<5;i++){
      		srt_client_send(sockfd2, mydata2, 7);
		printf("send string:%s to connection 2\n",mydata2);	
      	}

	//wait for a while and close the connections
	sleep(WAITTIME);

	if(srt_client_disconnect(sockfd)<0) {
		printf("fail to disconnect from srt server\n");
		exit(1);
	}
	if(srt_client_close(sockfd)<0) {
		printf("fail to close srt client\n");
		exit(1);
	}
	
	if(srt_client_disconnect(sockfd2)<0) {
		printf("fail to disconnect from srt server\n");
		exit(1);
	}
	if(srt_client_close(sockfd2)<0) {
		printf("fail to close srt client\n");
		exit(1);
	}

	//stop the overlay
	overlay_stop(overlay_conn);
}