Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about websocket's room #27

Open
culionbear opened this issue Feb 29, 2020 · 15 comments
Open

about websocket's room #27

culionbear opened this issue Feb 29, 2020 · 15 comments
Labels
question Further information is requested

Comments

@culionbear
Copy link

hello
I want to implement a function with websocket.
the details are as follows:
i want to create a room and the room will return me an id.
When someone connects to service using websocket,he can via id to find the room and connect it.
How do I implement it?....

@kataras kataras transferred this issue from kataras/iris Feb 29, 2020
@kataras kataras added the question Further information is requested label Feb 29, 2020
@kataras
Copy link
Owner

kataras commented Feb 29, 2020

Hello @culionbear, how are you?

I could prepare you an example right now as I use to but I am asleep and very tired at the moment, mostly because of that commit I design for several days. I will post you an example in a few hours, when I wake up, sounds good to you?

@culionbear
Copy link
Author

Hello @culionbear, how are you?

I could prepare you an example right now as I use to but I am asleep and very tired at the moment, mostly because of that commit I design for several days. I will post you an example in a few hours, when I wake up, sounds good to you?

thank you very much! : ) You really helped me a great favor!

@kataras
Copy link
Owner

kataras commented Mar 5, 2020

Hello @culionbear,

A Room has a "name" which can be used to Join and create (if first join) why don't you use that for identification ("id")?

@culionbear
Copy link
Author

@kataras Thank you for your reply!(^_^)
both room's name and number(key) can become id,it doesn't matter to me.
but in my game project,i want iris to create a room and two users can use websocket to join in this room.
i see iris'websocket has some method like 'roomjoin',so i think iris has mature mechanism to solve the problem.but i don't find the example about it.
can you provide a solution for me?thank you!

@kataras
Copy link
Owner

kataras commented Mar 5, 2020

They can join to the same room, that's the room feature, that client can communicate through a room (in the same namespace). A Room is created per connection on its first Join, after that you can just call nsConn.Room(name) *Room. The server accepts the rooms messages and transmit them to the corresponding clients, if a client is joined then it can accept a message, otherwise it can't.

Above all, you can create your own custom structures to hold those kind of data in your application, see for example the "user-conn" example located at: https://github.com/kataras/neffos/blob/master/_examples/wrap-conns-to-user/main.go.

I am preparing you an example, but before I proceed, take a look and tell me if this is something you want or if not please give me a code example on how you would imagine to write your websocket app's code.

image

@culionbear
Copy link
Author

culionbear commented Mar 5, 2020

@kataras
emmmmmm,i think the method 'create' is different from what I thought,
in my idea,for example,i have two service A and B,A is a normal service,B is websocket service.
Now two people want to play game.first A tells B that there will be two people playing the game after a while,and you must create a room (id=1).And then B create a room(It was not created automatically after person frist joined).
the room can wait two people connected with websocket.when someone is offline, another is win.And the room can also send message for them.
The rest is fine.
(Sorry my english is not good....QAQ)

@kataras
Copy link
Owner

kataras commented Mar 5, 2020

No worries about your english @culionbear, I am not a native english speaker too, you are totally fine. I just want to understand your use-case 100% before I push you an example.

So, you want A to tell B that there is a room to join (room name = "playerAplayerB_1"), if player B accepts the invitation then A is joining to the room and so the B. If player B disconnected then A wins. If that's the case I don't see any problems here.

Could you post down what is your current status of the implementation (code snippet) ? Where did you "stuck"?

@culionbear
Copy link
Author

@kataras
emmmmmm.....no!no!no!A and B is service,is not user.
Then I'll be more precise and say what I think.

in my idea,for example,i have two service A and B,A is a normal service,B is websocket service.
Now two people(C and D) want to play game.first A tells B that there will be two people(C and D) playing the game after a while,and you must create a room (id=1).And then B create a room(It was not created automatically after person(C or D) frist joined).
the room can wait two people(C and D) connected with websocket.when someone is offline, another is win.And the room can also send message for them.

i "stuck" in the method called "create",i wrote a demo one year ago,but the demo has lots of bug because I don't have good control over dropped calls and timeouts.

if you can speak chinese....
look at this:
现在有两个服务器A和B,服务器A是普通的iris服务器,B是有websocket功能的服务器,现在有两个人C和D想要开始玩游戏,他们先去A服务器进行匹配,如果匹配成功,A服务器会告诉B服务器有两个玩家要进入房间,这时B服务器会预先创建好一个具有唯一标识的房间,然后会告诉C和D房间号。
C和D就可以通过房间号进入该房间。

@kataras
Copy link
Owner

kataras commented Mar 5, 2020

I don't speak Chinese but I used google translate to read it. I understand the use-case now.

I have only one question so far, service A and service B are running on the same Iris instance, do they share the backend code or they are different servers and they should be communicate through an http client too? So, the HTTP web server (service A) should fire events to the websocket server(service B) and Service B should listen for service A in order to pass the messages to its websocket clients. Or, if they are sharing the same code, you could just use the server's Broadcast to broadcast messages from your http handler directly.

@culionbear
Copy link
Author

@kataras
emmmmmmm
you can understand that service B is not only iris's websocket service,it is alse a grpc service.
A and B aren't running on the same iris instance.
service A use grpc(steam) to connect B and tells B something.

@kataras
Copy link
Owner

kataras commented Mar 5, 2020

Ok I see there are different tech envolved here, could you send me a code to work on and improve for you?

Thanks,

@culionbear
Copy link
Author

@kataras
........I have some regrets,I cannot send you the code at present now,because Original game project in my another computer,and i can't go back to it(because of disease)....
Sorry

@culionbear
Copy link
Author

@kataras
but i can write a demo in these days,please give a bit time .(^_^)

@kataras
Copy link
Owner

kataras commented Mar 5, 2020

Ok np, so I have to write http, rpc, websocket game example and dockerize it, I will post back when I finish it. It will take some time because I am working on finalizing and relasing the new Iris version. Thanks!!

Be well and take care of your health!!

@culionbear
Copy link
Author

@kataras ok!no problem.
wish you success!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants