Receiving data

Hey, I’m trying to receive data from from my login server.

virtual bool Recv
(
    uint8 * Data,
    int32 BufferSize,
    int32 & BytesRead,
    ESocketReceiveFlags::Type Flags
) 

My implementation goes…

	uint8 Data;
	BYTE BufferSize;
	int32 BytesRead;
	bool sent = Socket->Recv(Data, BufferSize, BytesRead);

Can someone assist me please to where I have went wrong.

I just want to receive data please.

Edit: To show implementation

The following is server code, so once the client connects it will send a welcome banner to the client. It’s more of a testing to see if I can receive data from the server.

            NetworkStream ns = client.GetStream();
            connections++;
            Console.WriteLine("New client accepted: {0} active connections", connections);
            byte[] daata = new byte[1024];
            string welcome = "Welcome";
            ns.Write(Encoding.ASCII.GetBytes(welcome), 0, welcome.Length);
            ns.Flush();

//this is the C++ client code
Now after this is executed the client disconnects from the server, which I don’t understand, because the socket is streaming connecting orientated.

uint8 Data[1024];						//buffer size
int32 byteCount = 0;					//the number os bytes read
int32 dataSize = 0;						//the size of the data
Socket->Recv(Data, dataSize, byteCount); 
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(byteCount)); 
	if (byteCount >= dataSize)
		Socket->Recv(Data, byteCount, dataSize);

	//ToDO: capture the message, if true then connect to master server and open game lobby level

P.S - is there any further reading you can recommend?

Hello,

 uint8 Data;

This is your buffer, so it must be pointer to allocated space (“uint8 Data[1024]” or “Data = new uint8[1024]”) for example.
The buffer size is the limit of the buffer, to not write out of memory. If you follow my example, you should set BufferSize = 1024.
We generally set the buffer size between 256 and 4096, according to the quantity of data you are expecting.

Hi, does this mean, that the Data is what is being read into, then the Buffersize is the max amount of data it can hold? If so, then that makes BytesRead the message holder?

Data is where your received datas will be stocked.
BytesRead is the number of bytes that have been received. Like this, you can know the end of your message.
If BytesRead >= BufferSize, you should try to call recv again to get the remaining datas.

aah, I see. I attempted to get the remaining data, but I read 0 from the server.
if (dataSize >= (uint32)byteCount)
I know that I got something from the server, since it prints to the string, but I’m still getting 0 bytes, I’m sure that the variables were initialized properly as well.

Could you copy/paste your code around the recv call, including the declaration ?

Done.
Many thanks for not giving up on me!