Need suggests about RPC

Hi there.
I want to build a web application and there are several rooms in a hall that can hold a game. The problem is it seems that each room should be independent to handle their business, which means concurrency, but I don’t know how this could be done with RPC.
I do not think it is good to open one RPC service for each room, which means using multiple port.
But if I just use one RPC service and parse the room id in the args, then call the room’s function, the logic is sequential.
Is there any suggest? Thanks.

Hi, @Pierre_Ke, welcome to the Go forum.

What part of your web application needs RPC? Can you do what you want just with requests and responses and web sockets?

But if I just use one RPC service and parse the room id in the args, then call the room’s function, the logic is sequential.

Why not just service each request in a new gorountine?
This is how most servers in Go work.

One option may be to use several databases. Depending on what each room should do or store. One for each room. Add database rooms when needed. Connect direct, via REST API or RPC API.

Let’s say the room is for board games. Players in this game should choose to play a card or do some actions in turn.
And what I am doing now is open a RPC Service and register a HALL struct. In this HALL struct, I have a rooms slice. Now, when the a RPC request is coming, the args is like ‘{player: Pierre; roomID: 1; action: skip}’, the hall will parse the roomID then call this room’s handling function.
So what do you mean use several databases? I know I can use Redis ’s SUBSCRIBE&PUBHSIH to build a simple chat system for each room. But I don’t know how it works with RPC?

Sure. It is possible to use web sockets, but the problem is should I open a socket for each room? Does it use several ports?

It is my understanding that web sockets work similarly to the HTTP protocol where multiple clients all connect over the same port 443 and the multiplexing is handled at lower layers of the OSI model. There’s more information on the WebSocket - Wikipedia article, including examples in JavaScript and information about, e.g. the handshake and other implementation details.

As I understand it is about how long the player data will be stored. Will it be persistent, per page or per session? Or is there no need for storing? roomID indicates that there will be some sort of storing. Which means you need some storing - localStorage, REDIS or a real RDMS.

RPC in it self does no storing. You have to use Redis, Postgresql etc to store “room data”. RPC can only fire a function or make a request to another program for utilizing its service.