Results 1 to 3 of 3
Hi,
I want to send ten integers from 0-9 from a server to a client.
Both sides have a tcp and udp sockets.
The even numbers, 0 included, will be ...
- 02-26-2009 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 8
UDP TCP port problem
Hi,
I want to send ten integers from 0-9 from a server to a client.
Both sides have a tcp and udp sockets.
The even numbers, 0 included, will be sent thru the tcp.
The odd numbers will be sent thru the udp.
This is what I wrote but it gives me a bad address error by the recvfrom on the client side.
Client side
ServerPHP Code:
struct sockaddr_in server ;
server.sin_family = AF_INET;
inet_aton(argv[1],&(server.sin_addr));
server.sin_port = htons(atoi(argv[2]));
printf("UDP: Server Socket\n");
if( (udp_socket = socket (AF_INET,SOCK_DGRAM,0)) < 0 ){
somethingIsWrong("UDP", SOCKERR);
}
printf("UDP: Connect\n");
if ((connect(udp_socket, (struct sockaddr*)&server, sizeof(server))) < 0 ){
somethingIsWrong("UDP", CONCTERR);
}
printf("TCP: Connect\n");
if( (tcp_socket = tcp_connect(argv[1], atoi(argv[2]))) < 0 ){
somethingIsWrong("TCP", SOCKERR);
}
for( i=0 ; i < 10 ; i+=2 ){
if( (cur_received= tcp_receive(tcp_socket, buf, BUFFSIZE, 0 )) < 0 ){
somethingIsWrong("TCP", READERR);
}
printf("TCP- %i ", atoi(&buf[0]));
i++;
if( (cur_received = recvfrom(udp_socket, &buf, sizeof(buf),0,
(struct sockaddr *)&server, (socklen_t *) sizeof(server))) < 0 ){
somethingIsWrong("UDP", READERR);
}
printf("UDP- %i ", atoi(&buf[0]));
}
printf("\n");
PHP Code:
struct sockaddr_in server ;
struct sockaddr_in client ;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(atoi(argv[2]));
printf("Udp: Socket\n");
if( (server_udp = socket (AF_INET,SOCK_DGRAM,0)) < 0){
somethingIsWrong("UDP", SOCKERR);
}
printf("Bind UDP\n");
if(bind (server_udp, (struct sockaddr*)&server, sizeof(server))==-1){
somethingIsWrong("UDP", BINDERR);
}
printf("Establish tcp server\n");
// tcp_establish creates socket, bind it to port=argv[1] and listens
if( (server_tcp = tcp_establish(atoi(argv[1]), BACKLOG )) < 0 ){
somethingIsWrong("TCP", SOCKERR);
}
printf("New Client\n");
// accepts new clients
if( (client_tcp = tcp_get_connection(server_tcp, NULL )) < 0 ){
somethingIsWrong("TCP", ACCEPTERR);
}
for( i=0 ; i < 10 ; i++ ){
printf("%i ", i);
memcpy(buf, &i, sizeof(u_int));
if( tcp_send(client_tcp, buf, sizeof(int), 0) < 0 ){
somethingIsWrong("TCP", SENDERR);
}
i++;
memcpy(buf, &i, sizeof(u_int));
printf("%i ", i);
if( sendto(server_udp, buf, BUFFSIZE, 0, (struct sockaddr *) &client, sizeof(client) ) < 0 ){
somethingIsWrong("UDP", SENDERR);
}
}
printf("\n");
Any idea how to solve this problem ?
Thanks.
- 02-26-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 45
The problem was obviously posted at least thrice and is already solved:
- 03-04-2009 #3Just Joined!
- Join Date
- Nov 2008
- Posts
- 8
I will try and make admins delete them.


Reply With Quote