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"

What Includes are needed to set up Networking and Sockets?

After following tutorials to set up a connection to a tcp socket server, I have added the following code to my Player Controller class:


 void AMyPlayerController::P2Con()
     FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);
     int32 port = 19834;
     FIPv4Address ip;
     ip = FIPv4Address(127, 0, 0, 1);
     TSharedRef addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();


  PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "Networking", "Sockets", "InputCore" });

but things like ISocketSubsystem and FIPv4Address were either undefined or incomplete types. I figured this means I needed to include their header files, so I used documentation to obtain their header file locations and added the includes within MyPlayerController.h as follows:

MyPlayerController.h includes (not including the auto-generated)

 #include "Runtime/Networking/Public/Interfaces/IPv4/IPv4Address.h"
 #include "Runtime/Sockets/Public/SocketSubsystem.h"
 #include "Runtime/Core/Public/Templates/SharedPointer.h"

but including these files causes even more errors. I have tried just including Networking.h, and Sockets.h within their respective directories and it still has issues. I guess my question would be, what includes are needed to compile the above code, or is there an online resource which discusses including from modules such as Networking or Sockets? I'm very new to UE4 so I apologize if this question is trivial, but I've been stuck on this for hours so any help would be greatly appreciated. Thanks for reading!

Product Version: Not Selected
more ▼

asked Jun 06 '14 at 05:11 PM in C++ Programming

avatar image

21 1 2 5

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

2 answers: sort voted first

You need the following includes:

 #include "Networking.h"
 #include "Sockets.h"
 #include "SocketSubsystem.h"

The Socket API is a little difficult to use right now, but since you're already using it for most of your code anyway, you probably don't need the Networking module at all. The FinternetAddr class as a SetIp() overload that takes a string. Then you don't need the FIPv4Address.

If you're still getting compile errors, please post the errors.

more ▼

answered Jun 06 '14 at 05:37 PM

avatar image DrHobo Aug 24 '14 at 10:23 PM

This actually worked, @gmpreussner. Thanks.

avatar image IrishMTS Mar 16 '16 at 09:56 PM

@gmpreussner, I have the same addition to my build.cs file as the question, but Visual Studio tells me that it can't find "Networking.h". Any ideas why that might be?

avatar image gmpreussner STAFF Mar 16 '16 at 11:47 PM
     new string[] {

Or PublicDependencyModuleNames, depending on whether or not your module is exporting those types.

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

FIPv4Address is defined in IPv4Address.h, which is included from Networking.h, but you may find it easier to use FInternetAddr exclusively. You can conveniently set the IP address with the SetIp function that takes a string as a parameter and avoid the dependency on FIPv4Address entirely. You may need to add an #include for IPAddress.h, which defines FInternetAddr.

If you're still getting errors, please post a specific error so we can better diagnose it.

Also, you should be able to use just the filename in your #include paths. The full path (starting at the Runtime directory) should be unnecessary if the corresponding module is declared as a dependency, which in your case it appears to be.

more ▼

answered Jun 06 '14 at 05:29 PM

avatar image

Ryan Gerleve STAFF
1.1k 25 12 49

avatar image Zerotension Jun 06 '14 at 05:46 PM

After attempting to include header files

 #include "Networking.h"
 #include "Sockets.h"
 #include "IPAddress.h"

 Cannot open source file "Sockets.h"
 Cannot open source file "Networking.h"
 Cannot open source file "IPAddress.h"
 ISocketSubsystem: Incomplete type is not allowed
 FInternetAddr: Incomplete type is not allowed
 Argument list for class TSharedRef is missing

Brief overview of the errors I'm getting, it appears that the dependancies are not being loaded, is there more to adding a dependancy than simply inserting a string inside the Project2.Build.cs file?

avatar image gmpreussner STAFF Jun 06 '14 at 05:48 PM

No, that should be all that is needed. Do you actually have the full source code (or at least the header files) for the Engine? Sockets.h should be located in /Engine/Source/Runtime/Sockets/Public/

avatar image Zerotension Jun 06 '14 at 06:12 PM

Trying to just include without the directory does not work, including with the directory seems to load the headers, however references inside those files do not load their corresponding headers. i.e. Networking.h: cannot open source file "UdpSocketSender.h", "Sockets.h", "TcpListener.h" etc..

 #include "Runtime/Networking/Public/Networking.h"
 #include "Runtime/Sockets/Public/Sockets.h"
 #include "Runtime/Sockets/Public/SocketSubsystem.h"

causes these errors: http://pastebin.com/TnLFDm0T

so to sum it up, I have access to the members of the referenced classes now, but within those headers it cannot find any other referenced headers i.e. "TcpListener.h" inside Runtime/Networking/Public/Networking.h

avatar image Ryan Gerleve STAFF Jun 06 '14 at 08:53 PM

This sounds like a bug. Using 4.2 and a new "Basic Code" project, I was able to #include "SocketSubsystem.h" without errors after adding "Sockets" to the list of PublicDependencyModuleNames. Can you reproduce this problem with a new project? Are you using 4.2?

avatar image Zerotension Jun 06 '14 at 09:35 PM

I am using 4.2. Also on a new Basic Code project I am still getting a lot of errors, with the above code and the suggested includes (see below). I was hoping it was only an issue with Intellisense but it seems that is not the case. I could go into the MyProject3->Settings->NMake and add each and every library path to the Include Search Path list, but I'm not sure this will do anything except make intellisense less angry.

Errors on compile for new Basic Code project with socket code: http://pastebin.com/1ZiSHTH5

I will also state that without the posted code added to it, it does compile. Also it will compile with an include to "SocketSubsystem.h" but will display an intellisense error stating that it could not open the source file SocketSubsystem.h.

P.S. I did add Sockets and Networking to the dependancies in MyProject3.Build.cs before trying to compile*

 PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Networking", "Sockets" });

avatar image Ryan Gerleve STAFF Jun 06 '14 at 09:49 PM

It's unnecessary to add the library paths in the NMake settings. I understand it's annoying, but let's get you compiling before worrying about Intellisense.

If you use ISocketSubsystem::Get you will need to #include "SocketSubsystem.h", that's where the function is declared.

Looking at your other errors and the code in your original post, you are actually missing the template parameter on TSharedRef. CreateInternetAddr() returns a TSharedRef< FInternetAddr >. You can also specify auto to let the compiler deduce the type.

avatar image Zerotension Jun 06 '14 at 10:44 PM

Ahh it compiles now Ryan, thanks! Only problem now is the intellisense errors.

(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