Error on socket send

Hello,

I have a code that used to work until today. I use a FSocket created via FTcpSocketBuilder(…). The error is in my socket->send(…). As I said, it worked fine, but now it always fails to send data. Any insights to solve this?

FString result;
//Creating socket connection;
FIPv4Endpoint endpoint(FIPv4Address(address[0], address[1], address[2], address[3]), outport);
FSocket* socket = FTcpSocketBuilder(*socketName);
if (!socket->Connect(endpoint.ToInternetAddr().Get()))
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString(TEXT("Error connecting to webserver")));
	return FString(TEXT("Error connecting to webserver"));
}

//Send the request for the webserver
FBufferArchive buffer;
buffer << request;
int32 sent = 0;
if (!socket->Send(buffer.GetData(), buffer.GetTypeSize(), sent))
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Error sending %d bytes of data to webserver: %d.%d.%d.%d:%d"), sent, *(address + 0), *(address + 1), *(address + 2), *(address + 3), outport));
	return FString(TEXT("Error sending message webserver"));
}

What is the error?

It doens’t send the data (the function returns false and -1 bytes sent)

Can you post the whole code for the FTcpSocketBuilder initialization?

Edited the question with the part of the code

Hmm… not sure. One thing that looks wrong is buffer.GetTypeSize(). Did you mean buffer.TotalSize() ?

As far as the failed sending, your best bet would be step into socket code and see what error codes are returned.

Yeah, I just reinitialized the pc after realizing some other “zombie” process was using the socket…sight…thank you anyway! Also, I went back to my old “Fstring to uint8*” function, because that one wasn`t working…Looks like the problem is somewhere else now! gonna fix it! thank you! ^^

Also consider the AsReusable() method on the FTcpSocketBuilder. It will allow you to reuse the same port in multiple processes.

FSocket* socket = FTcpSocketBuilder(*socketName).AsReusable();