Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TheTempest

Question about casting data for using the send func

This topic is 5925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, the parameters for Winsock2''s send function are as follows: int send( SOCKET s, const char * FAR buf, int len, int flags ); i''m creating a data structure then casting it to a void stream: void *packet = (void*)&dataStruct; now my question is how to send this "packet" using the send func in winsock? if u just cast that pointer to a char pointer i get this error: Using WSAGetLastError was "WSAEINVAL (10022) Invalid Argument -- An invalid argument was passed to a function" Thanks...

Share this post


Link to post
Share on other sites
Advertisement
You should be fine simply casting the address of the data struct to a char * and using that as the parameter:

send(socket, (char *)&dataStruct, sizeof(dataStruct), 0);

Share this post


Link to post
Share on other sites
Why do you want to cast a void pointe to a char pointer? send() wants a char *, not a void *.

What kind of data do you want to send?

Kuphryn

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What are you using for your size parameter?
BTW, what johnnie2 said is almost correct, it should have been
send(socket, (char *)packet, sizeof(dataStruct), 0);
perhaps if that is not the answer you are looking for you could state your question more clearly?

Share this post


Link to post
Share on other sites
yes i agree, the question is so:

The send func takes a char* as its message buffer, but i''m casting my data struct to a void pointer like so:

void *dataPacket = (void*)&dataStructure;
send(connectedSocket,(char*)dataPacket,sizeoof(dataStructure),0);

now, i get an error from winsock when the program runs,
invalid parameter

Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hmm, can''t see anything straight-out wrong with that.
If the error is invalid parameter, the only thing i can suggest is that dataPacket must be NULL.
I am assuming btw, this is a runtime error, not a compile time error?
If it''s a run-time error, as far as i remember, send will only give you an invalid parameter if the flags don''t exist (0 is fine) or if the char* is NULL. (There is a special error for an invalid socket i think, and the size param is unsigned so it can''t be negative?)
So, yeah, all i can suggest is check that pointer for validity.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!