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(""));