I am using Winsock2 sockets to transfer some data over UDP. I am having difficulties passing the array into the sendTo() function to send the data.
I have wrote a mySocket class for future reuse and I have the following method currently, which works.
bool MySocket::sendData()
{
short int values[] = {1000,2000,3000,4000,5000};
int ret = sendto( sd,(const char*)values, sizeof(values) , 0, (sockaddr *)&sin, sizeof(sin) );
if(ret == SOCKET_ERROR)
{
return false;
}
return true;
}
Now I want to pass in a array instead of having
short int values[] = {1000,2000,3000,4000,5000};
So the new function would look like:
bool MySocket::sendData(short int data[])
{
short int * values = data;
int ret = sendto( sd,(const char*)&values, sizeof(data) , 0, (sockaddr *)&sin, sizeof(sin) );
if(ret == SOCKET_ERROR)
{
return false;
}
return true;
}
When the function is called the call would be:
short int data[] = {1000,2000,3000,4000,5000}; //Or some other pre-assembled list of short ints
if(socket->sendData(data))
cout << "Server: Packet Sent" << endl;
else
cout << "Server_Error: Packet failed to send" << endl;
I seem to just be getting the address of the pointer for data or values. I have been playing around with the "&" and pointers, but haven't found the correct way to transfer anything but the first number, which is where the pointer is pointing. I mostly write code in C# and switching back to C++ now has left my pointer skills pretty rusty.
How would I pass or use the passed in array to send it correctly?