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

How to use namespaces #46

Open
Mobinkarimi1 opened this issue Feb 27, 2023 · 8 comments
Open

How to use namespaces #46

Mobinkarimi1 opened this issue Feb 27, 2023 · 8 comments

Comments

@Mobinkarimi1
Copy link

Hi, how to connect to different namespaces?
I have a problem using namespaces and implementing them in the client, how to implement them in the client
Please help, any help would be helpful
Thanks

@Mobinkarimi1
Copy link
Author

https://socket.io/docs/v4/namespaces/
How to Client initialization?

@itisnajim
Copy link
Owner

this packagee it's a Wrapper for socket.io-client-csharp, so you can look there for further info.
according to:
doghappy/socket.io-client-csharp#112
you can do like this:

client = new SocketIOUnity("http://YOUR_SERVER_ADDRESS/your-namespace", new SocketIOOptions
{
    ...
});

@Mobinkarimi1
Copy link
Author

This solution creates a new socket connection, which is not ideal at all
I want to separate the application logic on a connection, for example, the login page has one namespace and the registration page has another namespace.

@itisnajim
Copy link
Owner

in the docs also they init multiple clients:
https://socket.io/docs/v4/namespaces/#client-initialization

const socket = io("https://example.com"); // or io("https://example.com/"), the main namespace
const orderSocket = io("https://example.com/orders"); // the "orders" namespace
const userSocket = io("https://example.com/users"); // the "users" namespace

you may want to check with the library's documentation or reach out to the developer at
https://github.com/doghappy/socket.io-client-csharp

@Mobinkarimi1
Copy link
Author

در اسناد همچنین چندین مشتری را راه اندازی می کنند: https://socket.io/docs/v4/namespaces/#client-initialization

const socket = io("https://example.com"); // or io("https://example.com/"), the main namespace
const orderSocket = io("https://example.com/orders"); // the "orders" namespace
const userSocket = io("https://example.com/users"); // the "users" namespace

ممکن است بخواهید اسناد کتابخانه را بررسی کنید یا با توسعه دهنده در https://github.com/doghappy/socket.io-client-csharp تماس بگیرید

ok , thanks

@Mobinkarimi1
Copy link
Author

your-namespace

io.in(my-namespace).emit("start game");
Apparently this solution is suitable, do you know how to use it in C#?

@itisnajim
Copy link
Owner

in your server and in your socket connection or in an event callback
call the below line to make the client attached to a room (e.g: 'your-room')

// inside io.on('connection', (socket) => {...}) 
// or inside socket.on('im-in', data => {...}) <== but for this event to be triggered in you c# you have to call socket.Emit("im-in");
socket.join('your-room');

after this call emit when needed
io.in('your-room').emit("start game");

@mrbaz1997
Copy link

mrbaz1997 commented Apr 15, 2023

can I use Dynamic namespace in client without create new socket connection?
the Namespace property only has getter and I can't change it

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

No branches or pull requests

3 participants