Jump to content
  • Advertisement
Sign in to follow this  

Unity .Net server and chat channels

This topic is 2029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im working on ARPG genre game with unity and i have been developing server by using vb.net 2010. Im running login , lobby and game sockets on ports 7111-7113 and each socket has own thread. example : When client connects login thread launch new thread and binds this new client data flow trought that.

here is picture to show logic behind my work :

But now to the my question. How i create channels? I want 16 player limited channels to chat and 8 players to ingame channel.

Think about this: my client send data , packet structure is [ID,DATA] = [0x01 ,"Hello/Channel1"]. Server must check from array or collection where to send this data. We know that i want send it to clients in Channel1. I have thinking about creating multidimensional array OR collection, collection would be nice because i can acces those client's easily.

AND second question.

How i can store channels to collection? I know how to use collection, so im not asking help for that. But im thinking of multidimensional collection , which inculdes variables Object and String. Object stays one of connected client and string has channel name. 

could it work ? tell me ! icon_biggrin.gif

I need some example code. Please help me!

Share this post

Link to post
Share on other sites

I don't think this is really about multiplayer specifically, but more about VB.Net data structures. So I'll move it over to General Programming.

Share this post

Link to post
Share on other sites

A simple Dictionary of channel name to members should work just fine in the simple case.

Yeah i think so, but could you drop me whit some example code?  I need some logic smile.png


I write here something what i have thinking.. 

every time when client connects server must send channel name to join. That channel must have less than 16 players inside. So can i have dictionary which have 


1. Collection of playerclients so i can communicate with them

2. Channel name

3. number of user on that channel 


Can i do like :

Dim LobbySockets As New Collection(Of LobbyConnection,String,integer)  

( LobbyConnection presents new instance of our class ,was made when the client connected)


Edited by Miraz

Share this post

Link to post
Share on other sites
I would make the channel be a binary ID in front of the text, rather than a substring within the payload.
Thus, the data could be:

[0x1, 0x5, "Hello"]
This would say "message type 1 (text chat) on channel 5, data "Hello".

The code for receiving command type 1 would then dispatch to the right channel:
Dictionary<byte, Channel> channels = new Dictionary<int, Channel>();

void DispatchChat(byte[] data) {
  Channel chan;
  if (!channels.TryGetValue(data[1], out chan)) {
    // no such channel
There are many other ways of slicing this (such as dispatching on channel first, command second, or using a different container, or targeting messages at "objects" where one kind of "object" is a "channel" or ...)

Also: One thread per user works for small numbers of users (a few hundred, say.) For good performance and resource utilization, though, you want to use BeginReceive()/BeginSend() or ReceiveAsync()/SendAsync() and let the OS do the thread pooling for you.

Share this post

Link to post
Share on other sites

Okey, thanks for solution. Im waiting if there is anybody else to share more ideas. 

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!