parent
4961bd5cab
commit
7a575339df
9 changed files with 89 additions and 5 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,56 @@ |
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "ShipsGameInstance.h" |
||||||
|
#include "WebSocketsModule.h" |
||||||
|
#include "Engine/GameEngine.h" |
||||||
|
|
||||||
|
void UShipsGameInstance::Init() |
||||||
|
{ |
||||||
|
Super::Init(); |
||||||
|
|
||||||
|
if (!FModuleManager::Get().IsModuleLoaded("WebSockets")) |
||||||
|
{ |
||||||
|
FModuleManager::Get().LoadModule("WebSockets"); |
||||||
|
} |
||||||
|
|
||||||
|
WebSocket = FWebSocketsModule::Get().CreateWebSocket("ws://localhost:8080/ws"); |
||||||
|
|
||||||
|
WebSocket->OnConnected().AddLambda([]() |
||||||
|
{ |
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "Connected to the server"); |
||||||
|
}); |
||||||
|
|
||||||
|
WebSocket->OnConnectionError().AddLambda([](const FString& Error) |
||||||
|
{ |
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, Error); |
||||||
|
}); |
||||||
|
|
||||||
|
WebSocket->OnClosed().AddLambda([](int32 StatusCode, const FString& Reason, bool bWasClean) |
||||||
|
{ |
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, "Connection was closed"); |
||||||
|
}); |
||||||
|
|
||||||
|
WebSocket->OnMessage().AddLambda([](const FString & MessageString) |
||||||
|
{ |
||||||
|
UE_LOG(LogTemp,Warning, TEXT("Received Message:")); |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "init is happening"); |
||||||
|
|
||||||
|
|
||||||
|
WebSocket->Connect(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UShipsGameInstance::Shutdown() |
||||||
|
{ |
||||||
|
if (WebSocket->IsConnected()) |
||||||
|
{ |
||||||
|
WebSocket->Close(); |
||||||
|
} |
||||||
|
|
||||||
|
Super::Shutdown(); |
||||||
|
} |
||||||
|
|
@ -0,0 +1,25 @@ |
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "CoreMinimal.h" |
||||||
|
#include "Engine/GameInstance.h" |
||||||
|
#include "IWebSocket.h" |
||||||
|
#include "ShipsGameInstance.generated.h" |
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/ |
||||||
|
UCLASS() |
||||||
|
class POINTBLANK_API UShipsGameInstance : public UGameInstance |
||||||
|
{ |
||||||
|
GENERATED_BODY() |
||||||
|
|
||||||
|
public: |
||||||
|
virtual void Init() override; |
||||||
|
virtual void Shutdown() override; |
||||||
|
|
||||||
|
TSharedPtr<IWebSocket> WebSocket;
|
||||||
|
|
||||||
|
}; |
Loading…
Reference in new issue