# Connecting to Socket Server

**URL:** <https://forums.unrealengine.com/t/connecting-to-socket-server/278768>\
**Category:** Multiplayer & Networking\
**Tags:** Networking, fsocket, unreal-engine, Multiplayer, UE4, CPP, question\
**Created:** [March 28, 2014, 4:22am UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768 "2014-03-28T04:22:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HailstoneRyan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HailstoneRyan](https://forums.unrealengine.com/u/HailstoneRyan)\
**Post date:** [March 28, 2014, 4:22am UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/1 "2014-03-28T04:22:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [March 28, 2014, 3:18pm UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/2 "2014-03-28T15:18:36Z")

</div>

_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.

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [March 28, 2014, 3:23pm UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/3 "2014-03-28T15:23:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [March 28, 2014, 3:28pm UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/4 "2014-03-28T15:28:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HailstoneRyan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HailstoneRyan](https://forums.unrealengine.com/u/HailstoneRyan)\
**Post date:** [March 28, 2014, 5:32pm UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/5 "2014-03-28T17:32:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![HailstoneRyan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HailstoneRyan](https://forums.unrealengine.com/u/HailstoneRyan)\
**Post date:** [March 28, 2014, 10:47pm UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/6 "2014-03-28T22:47:45Z")

</div>

Solved my linker error, missing “Sockets” in my dependency module.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_534c5e2a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_534c5e2a](https://forums.unrealengine.com/u/anonymous_user_534c5e2a)\
**Post date:** [April 9, 2014, 10:35am UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/7 "2014-04-09T10:35:06Z")

</div>

Could you tell me what you mean by dependency module?

i’m getting linker errors with the ISocketSubSystem…

---

<div class="post-metadata">

**Author:** ![HailstoneRyan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HailstoneRyan](https://forums.unrealengine.com/u/HailstoneRyan)\
**Post date:** [April 12, 2014, 3:06am UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/8 "2014-04-12T03:06:44Z")

</div>

In PROJECTNAME.Build.cs you need to add “Sockets” to PublicDependencyModuleNames

---

<div class="post-metadata">

**Author:** ![fikriemre](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fikriemre](https://forums.unrealengine.com/u/fikriemre)\
**Post date:** [February 27, 2015, 8:59am UTC](https://forums.unrealengine.com/t/connecting-to-socket-server/278768/9 "2015-02-27T08:59:09Z")

</div>

valla helal lan
