Advertisement

Packets in winsock - plz help...

Started by August 09, 2002 03:30 PM
3 comments, last by Baloogan 22 years, 6 months ago

struct MiniPacket
{
int Data;
};


// init winsock code... s is socket...



MiniPacket MiniBuffer;
MiniBuffer.Data = Hello;
			
send(s,(char *) MiniBuffer,sizeof(MiniBuffer),0);
 
Is this how would you put a struct into a packet?
If you were MEANT to understand it, we wouldn't have called it 'code'
Almost
You just need to get the address of the struct though using &
so you would do
send( s, (char*)&MiniBuffer, sizeof(MiniBuffer), 0 );

Just remember though, if you have a pointer in your struct, it will only send that 4byte pointer, and NOT the data that is being pointed to. Not sure about arrays either, i don''t think they would work though. So as long as you stick to primitives in your struct you should be ok.
Advertisement
THANK YOU!!!!!!!!!!!!!! now it works!!!!!!
If you were MEANT to understand it, we wouldn't have called it 'code'
quote:
Original post by Anonymous Poster
Not sure about arrays either, i don''t think they would work though.


Arrays work.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Cool, thanks. I guess arrays are allocated in the same memory as the rest of the struct aren''t they. Silly me

This topic is closed to new replies.

Advertisement