# Why I need to restart the editor in order to run the game as host by using FSocket?

**URL:** <https://forums.unrealengine.com/t/why-i-need-to-restart-the-editor-in-order-to-run-the-game-as-host-by-using-fsocket/335822>\
**Category:** Multiplayer & Networking\
**Tags:** Networking, fsocket, unreal-engine, UE4, question, CPP\
**Created:** [October 19, 2015, 6:45pm UTC](https://forums.unrealengine.com/t/why-i-need-to-restart-the-editor-in-order-to-run-the-game-as-host-by-using-fsocket/335822 "2015-10-19T18:45:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_fe4a0cd2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fe4a0cd2](https://forums.unrealengine.com/u/anonymous_user_fe4a0cd2)\
**Post date:** [October 19, 2015, 6:45pm UTC](https://forums.unrealengine.com/t/why-i-need-to-restart-the-editor-in-order-to-run-the-game-as-host-by-using-fsocket/335822/1 "2015-10-19T18:45:00Z")

</div>

I use FSocket to build connection and make my game run as host.  
I click “play” to test the game and it works and do get connecton.  
But after that, if I want to test my game again ,  
I need to restart the editor otherwise the accept function will not wait for connection but return NULL directly.  
How does it come? Is there any wrong with my code? Btw: I have closed the sock before I close the game.  
Below are how I build connection :

```
  FSocket* lisock;
    lisock = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);
    
    int32 port = 1111;
    TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
    
    addr->SetIp(FIPv4Address::Any.GetValue());
    addr->SetPort(port);
    
    lisock->Bind(*addr);
    lisock->Listen(8);
    
    TSharedRef<FInternetAddr> conaddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
    
    FSocket* consock;
    consock = lisock->Accept(*conaddr, TEXT(""));

```

---

<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:** [October 19, 2015, 9:39pm UTC](https://forums.unrealengine.com/t/why-i-need-to-restart-the-editor-in-order-to-run-the-game-as-host-by-using-fsocket/335822/2 "2015-10-19T21:39:28Z")

</div>

Are you closing the socket when the game shuts down?  
Also, this may help:

```
lisock.SetReuseAddr();

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fe4a0cd2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fe4a0cd2](https://forums.unrealengine.com/u/anonymous_user_fe4a0cd2)\
**Post date:** [October 20, 2015, 8:33am UTC](https://forums.unrealengine.com/t/why-i-need-to-restart-the-editor-in-order-to-run-the-game-as-host-by-using-fsocket/335822/3 "2015-10-20T08:33:32Z")

</div>

It works~thank you.  
I did not close the lisock when I shut down because it will crash if I do not connect to the game.  
I modify my code and it can be closed without problem.
