x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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"));
 }
Product Version: UE 4.9
Tags:
more ▼

asked Sep 16 '15 at 10:39 PM in C++ Programming

avatar image

lgss
1 1 2 5

avatar image gmpreussner STAFF Sep 16 '15 at 10:49 PM

What is the error?

avatar image lgss Sep 16 '15 at 11:05 PM

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

avatar image gmpreussner STAFF Sep 16 '15 at 11:07 PM

Can you post the whole code for the FTcpSocketBuilder initialization?

avatar image lgss Sep 16 '15 at 11:18 PM

Edited the question with the part of the code

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Sep 17 '15 at 12:15 AM

avatar image lgss Sep 17 '15 at 12:40 AM

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! ^^

avatar image gmpreussner STAFF Sep 17 '15 at 02:22 PM

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();
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question