client and UDP server send data but not receive (C windows)

1

Hello, I'm trying to create an application that performs data exchange on the network, so there is an initial connection using TCP sockets that is working normally, then comes the use of UDP sockets, however I can not perform data exchange, sendto function always returns the appropriate amount of bytes, for reading I use the select function to determine when data is available for reading, and never there, then the data from the server and the client never reach the destination. Sockets creation is done as follows:

Create the socket udp: socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)

Soon after I call the bind function, passing the soccket and a sockaddr_in structure constructed as follows:

    addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = INADDR_ANY;

::bind(sock_fd, (struct sockaddr*)&addr, sizeof(sockaddr));

I am using :: bind, because the name of the method that performs the operation is also bind and the VS was giving conflict

After the bind function I just call the recvfrom and sendto methods to read and send the data as follows:

read = recvfrom(sock_fd, data, length, 0, (struct sockaddr*)&o_addr, &l)
sent = sendto(sock_fd, data, length, 0, (struct sockaddr*)&o_addr, sizeof(struct sockaddr))

To determine whether any data exists for reading I call the select function as follows:

int r;
struct timeval tv = { 0, 0 };
fd_set fds;

FD_ZERO(&fds);
FD_SET(sock, &fds);

r = select(sock + 1, &fds, NULL, NULL, &tv);

if (FD_ISSET(sock, &fds))
    return true;
return false;

and in that case it always returns false, testing is being done on two different machines. If anyone can help me, I appreciate it.

    
asked by anonymous 26.12.2015 / 16:55

0 answers