hi forum i try to create some FSocket funcionallity in order to send some camera data, but i dont understand very well the internet stuff
i create 2 methods inside an actor component to keep things as simple as posible, 1 for create a listen socket and 2 for close the connection
bool UMyActorComponent::createSocket()
{
FIPv4Endpoint EndPoint(FIPv4Address(127, 0, 0, 1), 8080);
Socket = FTcpSocketBuilder("local").AsReusable().BoundToEndpoint(EndPoint).Listening(8);
return (!Socket) ? false : true;
}
void UMyActorComponent::closeSocket()
{
if (Socket)
{
Socket->Close();
delete Socket;
}
}
ok i am connected to myself, now in the tick the socket listen for connections
like this:
void UMyActorComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
if (!Socket) return;
//get the remote adress
TSharedRef<FInternetAddr> RemoteAddress = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
bool Pending = true;
// handle incoming connections
if (Socket->HasPendingConnection(Pending) && Pending)
{
//New Connection receive!
FSocket* ConnectionSocket = Socket->Accept(*RemoteAddress, TEXT("Received Socket Connection"));
if (ConnectionSocket != NULL)
{
print("one client online");
}
}
}
and now for my client i write a very dump example with javascript in html5:
<!DOCTYPE HTML>
<html>
<head>
<title> UE4 Client </title>
</head>
<body>
<button onclick="connectToUE()">Connect</button>
</body>
<script type="text/javascript">
function connectToUE()
{
if ("WebSocket" in window)
{
// Let us open a web socket
var ws = new WebSocket("ws://localhost:8080/echo");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
alert("Message is received...");
};
ws.onclose = function()
{
// websocket is closed.
alert("Connection is closed...");
};
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</html>
when i push my html button, the ue receive correctly the incoming connection and print my msg to the screen, but i afraid something fails in the handshake, because my function onopen in the html nevers calls, anyway the connection is done because when i end the connection in ue, so my html calls onclose event displaying the alert,
what is wrong here? why my client is not full open?