Announcement

Collapse
No announcement yet.

Need a TCP Listener that works on 4.19

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need a TCP Listener that works on 4.19

    I have now spent close to a month on trying to get a TCP Listener working in 4.19.

    I have tried every piece of sample code on the wiki, most of which was provided by Rama, but most of which have since been replaced by the FTCPListener class. In fact, I even tried his code without using the FTCPListener class especially given the doubt that exists if this class works correctly. The amount of churn about this topic over the last year or so is amazing. At some point people were discouraged from using FTCPListener and I am not sure that I have seen any post that gives the green flag to use it again.

    I did a search on Unreal Engine and TCP Listener for the last two years and tried every piece of code, and every variance that was provided. In one posting a company offered up code where they modified Rama's code. (Thread link: https://forums.unrealengine.com/deve...-python-script )
    That seemed to provide a good alternative using the FTCPListener class but then as you read down the thread you start to get the same symptom show up that I experienced. People that try the code and that realize, like I did, that the receive does not work for some reason. The waiting for pending connection signals an incoming connection. The accept works and then the receive delivers nothing and also no error message. When I do an initial send on connection (like some TCP Listeners do), the client sees that but the message from the client is not received. I tried every possible combination of the listening backlog, blocking, non-blocking, reusable, etc to no avail. In desperation I tried to make Unreal the client and run the server somewhere else. Very similar unstable results. Sometimes message replies are received into UE - other times they are simply lost.

    I wrote test clients and servers in C#, I used network testing tools that emulate TCP listeners and clients, I have run clients on repeat that connects every second and blasted UE to see if it is a timing issue (which I still think it is), but could not get predictable results. Once or twice when I would run UE in debug mode from Visual Studio and create a break point in the C++ code, the receive would magically work and the moment I run UE by itself and don't have insight into the code - the receive fails. Then I debug in C++ again but suddenly the receive even fails in debug.

    Whenever I test the non-UE listeners and clients I wrote and/or the test tools against each other, everything works perfectly. This is, after all not rocket science and I have created many listeners on different platforms in different languages from Assembler, C, C++, Java, and now C#. This is easy - the kind of stuff you give a junior programmer to do.

    But the mushy mass of library upon library in the TCP category - in order to provide a universal socket library for all - seems to have created a socket library for nobody. One Epic support person/or developer referred to code rot inside the TCP library area - presumably referring to the FTCPListener library. Another symptom of that - the amount of socket libraries for sale on Epic Marketplace. Which honestly might be my last resort.

    But could Epic perhaps intervene here and present us with the simplest of sample code that will run an echo TCP Listener on UE on Windows (which I assume is a fairly large part of the user community). Perhaps you could even blueprint enable it and then it is something we can run as each release comes out to ensure that the socket library is still working. I am willing to help in whichever way you need me to get this into existence.

    I don't mean to be disparaging but come on Epic, those C++ Reference libraries you generate from code is not helping us. Awesome individuals like Rama makes it better but sometimes it makes it worse because his code gets stale and then it suddenly doesn't work on the latest release of Unreal and confuse the people looking at it. I almost hesitate to ask because at this stage getting a reliable TCP listener will be like a miracle. But it is logical to want to make a listener not run on the game thread - hence the FRunnable heritage of FTCPListener I presume. But this would be the right way to provide the code.

    I do have appreciation for the challenge of getting all this functionality to work on so many platforms. I have been in a similar situation with C++ products that was deployed on many different hardware platforms so I understand the challenge. But we need you help here...


    #2
    Hey Corneel!

    I'm working on 4.20.1 at the moment and was looking into a TCP connection.

    I came across this -- https://forums.unrealengine.com/comm...ueprint-plugin -- if you haven't seen it already.

    It's a great little plugin made by use HowToCompute, with a lot of it being adapted from Rama's work. But I got it working in 4.20.1! Just created a C++ project and pasted the code over, set up the blueprint nodes, used Hercules as a listen server! And it's all connected.

    Hope this helps!

    - Cleava
    Last edited by Timehacker_; 08-07-2018, 08:17 AM.

    Comment


      #3
      Been using TCP and not replication since 4.13. But using a custom TCP implementation and nothing of Epic's.

      One issue you might be running into is where you read the TCP messages. You can only update Unreal objects during the game Tick(). Thus our implementation reads the incoming TCP queue during GameMode.Tick().

      Comment


        #4
        Cleava, I tried your recommendation but I get an error that says the plugin is not compatible with 4.20. Did you get any errors like that?

        Comment


          #5
          Also, I just realized that Socketer does not implement a TCP Server - only a client

          Comment


            #6
            Hi Corneel

            I had the same problem as you and couldn't rebuild the plugin. I created a C++ Project and created my own C++ Class for the TCPActor, and created my own UObject for the Socket, and copied the code over.

            I then created a blueprint class from the C++ actor and mapped the plugins as shown in his video.

            Let me know if you need any of the files I have if you can't get it to work further.

            And yes, the socketer only works as a client, however for the project I'm on I needed an external server anyway.

            - Cleava

            Comment


              #7
              Rama Do you have any advice for us? Where can we get a TCP Listener class that works in 4.20 ?

              Comment


                #8
                Here is something to play around with. It should give you some ideas. It is a work in progress, so don't expect it to be perfect. I pulled it from a project I'm working on, so some of the code may not be relevant, but I tried to remove what I could to make it more focused on the server listening and client connections. The threading is not really great compared to, say, the TCPMessaging module, which has a much more robust way of implementing threads, but it should be fine for a simple TCP server that can support a few client connections. More info is in the README, Anyway... hope it helps. K-BOB
                Attached Files

                Comment


                  #9
                  K-Bob-a-lu-bob thank you, the code looks promising. I was doing some tests and got this exception on the shutdown of the game. But while it was running it seemed to be working perfectly.

                  Access violation - code c0000005 (first/second chance not available)

                  UE4Editor_TCPServer!FTCPServer::SendMessage() [c:\users\corne\downloads\tcpserver\tcpserver\source\tcpserver\tcpserverimp.cpp:289]
                  UE4Editor_TCPServer!FTCPServer::Run() [c:\users\corne\downloads\tcpserver\tcpserver\source\tcpserver\tcpserverimp.cpp:189]
                  UE4Editor_Core!FRunnableThreadWin::Run() [d:\build\++ue4+release-4.19+compile\sync\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:76]

                  Comment


                    #10
                    K-Bob-a-lu-bob I also just noticed that nothing the server sends to the client is actually received on the other side. I was using PacketSender to send a message every few seconds. This looks very similar to what I have been struggling with. The server receives the message from the client but the reply is lost.

                    Comment


                      #11
                      I will take a look at it with PacketSender when I get a chance and see why server reply is not making it back to the client... and why there are exceptions on shut down...

                      Comment


                        #12
                        Corneel Just a quick question... are you trying, or expecting, an echo response? If so, you will have to change the way the server is coded to respond. The server is currently setup to respond to a login. You should get a message to either confirm the name and password worked or was not correct... In the project I pulled it from, I have the server query a database for the name and password, and send a response to the client... I tried PacketSender with the server and had no issues, it was responding with a message to the login information sent, like "Hello zak", or "Name or Password is not valid"... I'm still not sure about the exceptions... I will keep looking into those... Not sure if it is relevant, but I'm using Windows 7 and Visual Studio 2017... also, if you have any virtual machines set up, the virtual ethernet adapters can cause problems, so they have to be disabled when testing things out.

                        Comment


                          #13
                          K-Bob-a-lu-bob it seems to have a problem with the server control ref variable. But I got it working in the end.

                          You set the variable at startup but it has a problem that when it wants to send the reply it doesn't seem to be ready for use. It sends the message: Accessed None trying to read property ServerControlRef. I then set the variable from the level blueprint and it seems to have solved the problem.

                          Unreal game log of variable not being set:

                          LogBlueprintUserMessages: [ServerControl_48] IP Address: 127.0.0.1 Port Number: 8080 Connection Timeout: 30
                          LogTemp: Warning: The split string is - Name: Bob, Password: BigD23, ClientID: E621E45845E7B84765F63FA0C216C64C, Location: 32,54,78, Rotation: .56,.34,.78,1
                          PIE: Play in editor start time for /Game/UEDPIE_0_Server 0.509
                          LogBlueprintUserMessages: Late PlayInEditor Detection: Level '/Game/Server.Server:PersistentLevel' has LevelScriptBlueprint '/Game/Server.Server:PersistentLevel.Server' with GeneratedClass '/Game/Server.Server_C' with ClassGeneratedBy '/Game/Server.Server:PersistentLevel.Server'
                          LogStats: Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//FTcpListener///Thread_6b30_0///####STATCAT_Advanced#### old //STATGROUP_Threads//FTcpListener///Thread_6868_0///####STATCAT_Advanced####
                          LogStats: Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP_Threads//MyThreadName1///Thread_69e8_0///####STATCAT_Advanced#### old //STATGROUP_Threads//MyThreadName1///Thread_5c28_0///####STATCAT_Advanced####
                          LogBlueprintUserMessages: [ServerControl_48] Hello
                          PIE: Error: Blueprint Runtime Error: Accessed None trying to read property ServerControlRef from function: 'ExecuteUbergraph_ServerControl' from node: Send Message in graph: EventGraph in object: ServerControl with description: Accessed None trying to read property ServerControlRef
                          LogBlueprintUserMessages: [ServerControl_48] Hello


                          The result of the successful test: Here is the log of the trace tool.

                          TIME From IP From Port To IP To Port Method Error ASCII Hex
                          13:40:05.478 You 59493 127.0.0.1 8080 TCP zak:gamer2 7a 61 6b 3a 67 61 6d 65 72 32
                          13:40:05.479 127.0.0.1 8080 You 59493 TCP \nHello zak\n 0A 48 65 6C 6C 6F 20 7A 61 6B 0A
                          13:40:05.883 127.0.0.1 8080 You 59493 TCP

                          One last question. Now that it works it generates an insane amount of the same message:

                          LogTemp: Warning: The Client ID is: CC8524D34C77A418870033A3067052BA
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1
                          LogTemp: Warning: Client connection timeout is: 1

                          Is this normal? Thanks for all your help and patience.

                          Comment

                          Working...
                          X