Winsock & double in C?
May 2, 2013 at 12:32am UTC
Hello all,
I'm trying to send a double array using UDP over the Internet. I did establish the connection between Client/Server and I sent char data in Winsock. Now, I'm going to get data from a device and send it to the client.
Server
1 2 3 4 5 6 7 8 9 10 11 12 13 14
double p[3];
if (currentData.m_buttonState && !prevData.m_buttonState)
{
p[0] = currentData.m_devicePosition[0];
p[1] = currentData.m_devicePosition[1];
p[2] = currentData.m_devicePosition[2];
}
//send the message
if (sendto(socket, (char *)&p[0],strlen((char *)&p[0]) , 0 , (struct sockaddr *) &ss, sizeof (ss)) == SOCKET_ERROR)
{
printf("sendto() failed with error code : %d" , WSAGetLastError());
exit(EXIT_FAILURE);
}
Client
1 2 3 4 5 6 7 8 9
#define Buffer_size 512 //Max length of buffer
#define PORT 222 //The port
char buffer[Buffer_size ];
if ((recv_len = recvfrom(s, buffer, Buffer_size , 0, (struct sockaddr *) &ss, sizeof (ss)) == SOCKET_ERROR)
{
printf("recvfrom() failed with error code : %d" , WSAGetLastError());
exit(EXIT_FAILURE);
}
In client, I'm getting nothing. What am I doing wrong?
May 2, 2013 at 7:56pm UTC
Thank you. I did figure it out.
Topic archived. No new replies allowed.