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"

FSocket Connection breaks

I am using an Fsocket to receive data from a remote client. The socket is setup much the same way as in this example: https://wiki.unrealengine.com/TCP_Socket_Listener,_Receive_Binary_Data_From_an_IP/Port_Into_UE4,_(Full_Code_Sample)

I am now only testing over localhost/127.0.0.1 and receiving data from a python script. The data is recieved when a user presses a key and the function TCPReceiveData, listed below, is called.

 TArray<uint8> ANetwork::TCPReceiveData(uint32 BytesToRead)
 {
     if (!ConnectionSocket) {
         return TArray<uint8>();
     } else if ( ConnectionSocket == (FSocket*)0xdddddddddddddddd) {
         return TArray<uint8>();
     }
     
     TArray<uint8> ReceivedData;
     FTimespan BlockTime(0, 0, 5); // block wait for 5 secs
     if ( ConnectionSocket->Wait(ESocketWaitConditions::WaitForRead, BlockTime )) {
         ReceivedData.Init(BytesToRead);
         int32 Read = 0;
         ConnectionSocket->Recv(ReceivedData.GetData(), BytesToRead, Read);
     } else {
         return TArray<uint8>();
     }
     
     if (ReceivedData.Num() <= 0) {
         return TArray<uint8>();
     }
     
     return ReceivedData;
 }

After reading from the socket anywhere between 10 and 50 times the connection breaks and it enters the following if statement:

 if ( ConnectionSocket == (FSocket*)0xdddddddddddddddd) {
         UE_LOG(LogTemp, Log, TEXT("ConnectionSocket == 0xdddddddd"));
         return TArray<uint8>();
     }

And I cannot read from the socket anymore. This happens very unregularly and I cannot for the life of me figure out how to solve this

Product Version: UE 4.7
Tags:
more ▼

asked Jul 23 '15 at 07:24 PM in C++ Programming

avatar image

SimenA
15 3 7 10

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

1 answer: sort voted first

It is possible that your Socket has been GC by the reflection system.

more ▼

answered May 11 '16 at 07:02 PM

avatar image

qiuwch
61 4 5

(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