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"

Connecting to Socket Server

I've done what reading I can in the documentation so far, and I believe I'm on the right track but perhaps someone can correct me.

I'm attempting to connect to a custom socket server rather than a dedicated server run by players.

From my understanding doing this would involve FSocket, ISocketSubsystem, and FInternetAddr.

So far I've attempted to compile the following.

FSocket *socket = ISocketSubsystem::Get()->CreateSocket("default", "default", false);

Now I understand why this isn't working, because ISocketSubsystem is an interface. What class implements this interface? How should I be using these classes? Has anyone done anything like this yet, or attempted to?

Product Version: Not Selected
Tags:
more ▼

asked Mar 28 '14 at 04:22 AM in C++ Programming

avatar image

HailstoneRyan
714 39 26 54

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

2 answers: sort voted first

ISocketSubsystem::Get() returns a singleton for the running platform's socket subsystem. It is this singleton that implements the ISocketSubsystem interface, which is why your example code works. You will likely stumble upon this pattern in other places as well.

In the Networking module there are two helper classes, FTcpSocketBuilder and FTcpListener, for TCP clients and servers respectively. Please note that this module is currently not documented, and the API may change in the future, so use it with care. At the very least, it will provide you with some examples on how to create sockets in UE4. Look at FTcpSocketBuilder::Build() to see what it is doing. The module also contains helper classes for UDP sockets.

In particular, note that, after creating a socket you will also have to bind to a port and possibly perform other initialization steps in order to establish a connection to your server.

more ▼

answered Mar 28 '14 at 03:18 PM

avatar image HailstoneRyan Mar 28 '14 at 05:32 PM

When I use ISocketSubsystem::Get() I get a linker error.

Looking at the FTcpSocketBuilder class I have a few questions you can hopefully answer.

  • Do I need to define the BoundToAddress, and BoundToEndPoint?

  • Does the port it's bound to on the client need to match the port the server is using?

  • Is there anything that absolutely needs to be defined in that class before building the socket?

avatar image HailstoneRyan Mar 28 '14 at 10:47 PM

Solved my linker error, missing "Sockets" in my dependency module.

avatar image fikriemre Feb 27 '15 at 08:59 AM

valla helal lan

avatar image Dave4723 Apr 09 '14 at 10:35 AM

Could you tell me what you mean by dependency module?

i'm getting linker errors with the ISocketSubSystem...

avatar image HailstoneRyan Apr 12 '14 at 03:06 AM

In PROJECTNAME.Build.cs you need to add "Sockets" to PublicDependencyModuleNames

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

You're better off creating it that way (assuming TCP):

FSocket *socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSSTEM)->CreateSocket(NAME_Stream, TEXT("My server socket"), false);

There's a number of socket subsystem in the engine and more than one can be present at a time, so providing PLATFORM_SOCKETSUBSYSTEM is safer.

more ▼

answered Mar 28 '14 at 03:23 PM

avatar image

RCL STAFF
2.7k 59 6 88

avatar image RCL STAFF Mar 28 '14 at 03:28 PM

Nevermind, builder approach suggest by Max is cleaner, however you can still use that code if you need to know the guts.

(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