HELLO,
I’ve been looking for a solution for several weeks.
I have 2 dedicated servers, which I would like to communicate together, it is not a constant flow. This is why once used, I would like to close it. I would like to keep the same process when the client connects to the server (Because I do not want to open several ports for a single server).
DEFINE_CONTROL_CHANNEL_MESSAGE(FnaGameText, 31, FString);
Here are two of the most conclusive tests:
-
The same method as UE, It accepts the communication But I never receive My data, And subsequently, crashes the server (sends).
if (GEngine->CreateNamedNetDriver(World, NAME_PendingNetDriver, NAME_GameNetDriver))
{
NetDriver = GEngine->FindNamedNetDriver(World, NAME_PendingNetDriver);
UE_LOG(LogNet, Error, TEXT(“get FindNamedNetDriver .”));
}
if (NetDriver.IsNull())
{
UE_LOG(LogNet, Error, TEXT(“Error initializing the pending net driver. Check the configuration of NetDriverDefinitions and make sure module/plugin dependencies are correct.”));
return;
}UIpNetDriver* NetDriverW = Cast(World->GetNetDriver());
NetDriver->NetConnectionClass = NetDriverW->NetConnectionClass;
NetDriver->SetWorld(World);// NETWORK_PROFILER(GNetworkProfiler.TrackSessionChange(true, URL));
if (NetDriver->InitConnect(this, URL, ConnectionError))
{//FNetDelegates::OnPendingNetGameConnectionCreated.Broadcast(this); UNetConnection* ServerConn = NetDriver->ServerConnection; if (ServerConn->Handler.IsValid()) { ServerConn->Handler->BeginHandshaking(FPacketHandlerHandshakeComplete::CreateUObject(this, &UFliconaNetworkNotify::SendMessage, Message)); } else { SendMessage(Message); }
}
else
{
UE_LOG(LogNet, Warning, TEXT(“error initializing the network stack”));GEngine->DestroyNamedNetDriver(this, NetDriver->NetDriverName); NetDriver = NULL; if (ConnectionError.Len() == 0) { ConnectionError = NSLOCTEXT("Engine", "NetworkInit", "Error initializing network layer.").ToString(); }
}
void SendMessage(FString Message)
{
if (NetDriver != nullptr)
{
UNetConnection* ServerConn = NetDriver->ServerConnection;
if (ServerConn != nullptr)
{
if (ServerConn->Handler->IsFullyInitialized())
{
FNetControlMessage<NMT_FnaGameText>::Send(ServerConn, Message);
ServerConn->FlushNet();
UE_LOG(LogTemp, Log, TEXT(“Sent custom message: %s”), *Message);
}
else
{
UE_LOG(LogTemp, Error, TEXT(“Packet handler is not fully initialized.”));
}
}
}
}
- I don’t really like this method Because I can only use IpNetDriver As a communication method It accepts communication But I never receive My data.
UIpNetDriver* NetDriverW = Cast(World->GetNetDriver());
FSocket* Socket = NetDriverW->GetSocket();
if (Socket)
{
TSharedRef Address1 = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
const TCHAR* IP = TEXT(“127.0.0.1”);
bool bIsValid;
Address1->SetIp(IP, bIsValid);
Address1->SetPort(1777);
if (bIsValid)
{
UE_LOG(LogTemp, Log, TEXT(“Adresse IP valide: %s”), IP);
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“Adresse IP invalide: %s”), IP);
}
TArray<uint8> DataBuffer;
DataBuffer.Add(31);
DataBuffer.Append(Message);
int32 BytesSent = 0;
CLOCK_CYCLES(NetDriverW->SendCycles);
bool bSent = Socket->SendTo(DataBuffer.GetData(), DataBuffer.Num(), BytesSent, *Address1);
UNCLOCK_CYCLES(NetDriverW->SendCycles);
if (bSent && BytesSent == DataBuffer.Num())
{
UE_LOG(LogTemp, Log, TEXT("Message envoyé avec succes"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Échec de l'envoi du message"));
}
}
- The receipt code is in World.
NotifyControlMessage(UNetConnection* Connection, uint8 MessageType, FInBunch& Bunch)
{
switch(MessageType)
{
case NMT_FnaGameText:
{
FStringText;
if (FNetControlMessage<NMT_FnaGameText>::Receive(Bunch, Text))
{
UE_LOG(LogTemp, Warning, TEXT(“received Text: %s”), *Text);
}
break;
}
…
Thanks!