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


Receiveing text from a function - damnit!!!

Recommended Posts

MindWipe    940
Hello! For a time now I''ve had this really annoying problem. I''m making a WinSock Wrapper and I just can''t get my receive function to work. Here is how the receive function looks for the moment. Probably really stupid made. But anyway:
mWinsock::Receive(char *ReceiveBuffer)
	char rBuffer[80];

	ReceiveBuffer = new char [80];

	recv (mSocket, rBuffer, sizeof(rBuffer), 0);
I want the function to fill a char Buffer[80] with the text it receives from recv.
mWinsock Connection;
char buffer[80];

Connection.Receive(buffer); <- won''t work


recv (Connection.mSocket, buffer, sizeof(buffer), 0); <- works

How would you do it? "If it doesn''t fit, force it; if it breaks, it needed replacement anyway."

Share this post

Link to post
Share on other sites
Vaporisator    122
mmmh, I could be wrong, but shouldn''t you declare
char buffer[80]; as a pointer:
char *buffer[80];

you could also try:

or try

char *buffer = (char*)malloc(80);

hope that helps (works)!

Yesterday we still stood at the verge of the abyss,
today we''re a step onward!

Share this post

Link to post
Share on other sites
Prosper/LOADED    100
When you do :

ReceiveBuffer = new char [80];

You make ReceiveBuffer pointing on another buffer than the one which was actually given to then function. Moreover, sizeof(aPointerToChar) won''t give you the length of the pointed string but the size of the pointer itself (4 bytes on most 32 bits systems). Anyway, you just have to do something like this :


mWinsock::Receive(char *ReceiveBuffer, int sizeOfBuffer)
memset( ReceiveBuffer, 0, sizeOfBuffer);
recv (mSocket, ReceiveBuffer, sizeOfBuffer, 0);

void main()
const int BUFFER_SIZE = 80;
char buffer[BUFFER_SIZE];
Connection.Receive( buffer, BUFFER_SIZE);

Share this post

Link to post
Share on other sites