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

Asked

Viewed 243 times

1

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

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

soon after I call the bind function, passing the soccket and a sockaddr_in structure built 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));

am using ::bind, because the name of the method that performs the operation is also bind and 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 if there is any data 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 this case it always returns false, the test is being done on two different machines. If anyone can help me I thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.