Websocket for ExtendApp

Hi there,

I am making a H5 game basing on the WebGL. I set up the WebSocket server on the extend app sharing the same Service URL. It works fine locally with the ws protocol. But when I deployed it to the cloud and change it to wss, I got an error like:

wscat -c wss://■■■■■.prod.gamingservices.accelbyte.io/ext-■■■■■-ExtendLogicServer/wslogic
error: Unexpected server response: 403

I wrote some test code and confirmed that the request did not reach the extend go gateway.
So I need your help to identify the reason.

Thanks!

BR//LuDong

Hi @user18
The team will take a look shortly.

Hi @user18 , I’m Eric, an SE from the Extend team.

This might be due to the missing of the bearer token in the auth header due to PLUGIN_GRPC_SERVER_AUTH_ENABLED being turned on, since at the AB hosted environment, environment variable PLUGIN_GRPC_SERVER_AUTH_ENABLED is by default set to true for security reason if not specified (saw that you don’t have it set for your app on the Admin Portal). Which means the Bearer token will have to be attached to the header via the wscat command, like this:

wscat -H “Authorization: Bearer <BEARER_TOKEN>” -c “wss://redacted.prod.gamingservices.accelbyte.io/ext-redacted-ExtendLogicServer/wslogic/”

This also coincides with the 403 error meaning forbidden.

As a sanity test, could you temporarily set PLUGIN_GRPC_SERVER_AUTH_ENABLED=false and retry with what you are already doing? If that works, follow up by either removing this env var or setting it to true, and attach a Bearer token as shown above?

I wrote some test code and confirmed that the request did not reach the extend go gateway.
On the other hand, just to make sure we are aligned, could you elaborate what you did exactly?

Thanks,
Eric

Hi,

Did you mention that you are able to create websocket service using Extend Service Extension and it works locally? It is interesting. Could you elaborate more on this?

This is because Extend Service Extension app relies on gRPC-Gateway | gRPC-Gateway Documentation Website and it does not support websocket right now. And in the Introduction to Service Extension | AccelByte Documentation, only RESTful service is mentioned and not websocket.

Regards,

Dhanar

Hi Eric,

Nice to meet you!

I have another grpc interface. It works fine without the Auth header.
So I believe the root cause may lie in somewhere else.

I will try later though.

BR//LuDong

Hi @dhanarab ,

I can confirm it works locally. It is an echo server at the moment, like

> hooyah@noodle-Macmini:~$ wscat -c ws://localhost:8000/ext-■■■■■-ExtendLogicServer/wslogic
Connected (press CTRL+C to quit)
> a
< a
> quit
< quit

There are 2 small changes:

  1. the server: setup the websocket server on the server side with package:NuGet Gallery | websocket-sharp-Net6.0 1.0.3.1
  2. the gateway: import “GitHub - pretty66/websocketproxy: 🔥🔥🔥Go websocket proxy, a simple websocket reverse proxy implementation, supports ws, wss” as a revese proxy, and mux it as
	mux.HandleFunc("/ext-■■■■■-ExtendLogicServer/wslogic", wp.Proxy)

Then it works locally.

On the cloud, I tried

curl https://■■■■■.prod.gamingservices.accelbyte.io/ext-■■■■■-ExtendLogicServer/wslogic
Must be a websocket request

the request did reach the gateway but got rejected because of the wrong scheme.

But with

wscat -c wss://■■■■■.prod.gamingservices.accelbyte.io/ext-■■■■■-ExtendLogicServer/wslogic

I added some other logs but I didn’t see the logs. The request seems be ban before the gateway.

And for a ws workflow, it is HTTP method at the beginning but with the Upgrade request instead of the Get/Post/Put method.

BR//LuDong

Hi @user18
I’m Vincent, Extend Product Manager.
Currently, Extend doesn’t support websocket. That’s the reason the server doesn’t receive your wscat request.

Can you share what your Extend app does in general and what’s the reason you need to use Websocket? Is it acting as a game server, e.g. calculating game physics? This will help us understand your use case so we can recommend the best solution with AGS.

Note
As a reminder, please don’t share any sensitive information as this is a public forum.

Hi @vincentab ,

Nice to meet you! It is good to have you here!

I hope the Extend app acts as an logic server in our game. It is nothing about the game physics or the scene simulation. It is like player upgrade or the equipment upgrade, but more complex. It may have some timers with it. So the server may send a message to the client at any time.

And to reduce the latency of each request, I want to use the the Bi-directional streaming. Unfortunately, it is not supported on the WebGL platform. On the WebGL platform, I am afraid I have no choice other than WebSocket. And on the server, it is quite easy to integrate it to the server. So that is it.

BR//LuDong

1 Like

This is great. Thanks @user18 !

Let me get back to the team and see if there are things we could do to help you resolve this use case.

Hi @user18 ,
In other words, you’re looking to use websocket so you can push information from the Extend app into your game client with low latency. Let me know if I understand this correctly.

Another question. Are you looking to send a request from the game client to the Extend app as well?

Yeah, beside the latency, I need the Bi-directional streaming. Then the server is able to send notice msg to the client. The gRpc on WebGL doesn’t support this feature.

Yes, if the websocket works, I will serialize the request and the response message myself.

BR//LuDong

Hi @user18
Understood. Thanks for the context.

We will review and share our thoughts about your use case.

Hi @user18 ,

You can utilize Lobby service API to send lobby websocket message to player. Your game client can send request to your Extend app via REST API. Upon receiving the request, your Extend app can send a notification to Lobby service, and then Lobby service will forward that to player if they are already connected to Lobby WebSocket.

To be able sending a web socket message via Lobby service, first you will need to create a topic first. For templated message, you will need to create a template first.

You can find relevant endpoints in here

For topic creation, you can use following endpoint or add it manually in admin portal.

To send the message you can use following endpoints:

Hope this helps.

Hi @user18

For additional information, you can use C# Extend SDK to call those Lobby service endpoint

FreeFormNotification
notificationWithTemplate
freeFormNotificationByUserID
notificationWithTemplateByUserID

You can take a look at our C# Extend SDK readme to get started

Hope this helps.

@rinardi are your responses the result of the discussion @vincentab had with the team? I’m super curious as to how valid of a use case this actually is.

Hi @njupshot
Yes. This is what we think could help resolve this use case. One of our customer does this as well. Let us know if that answer your questions!

It does, thank you @vincentab. It sounds like there’s potential for Extend to act as a game server given that streaming state isn’t needed. For example a turn based game could use your flow above where inputs are sent via HTTP to an extend app, who could then read/write the game state to/from cloud save and then push state changes back to the clients via lobby service websocket. I guess the only unknown there is how matchmaking would fit in.

1 Like

That’s an interesting use case! However, it’s an uncharted territory as Extend is not designed to be a game server. There are possibilities that the developer needs to build other functionality besides matchmaking integration to use Extend as a game server.