.Net server and chat channels

Started by
4 comments, last by purri 11 years ago

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 :

[attachment=14457:TCPServer.jpg]
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!

Advertisement

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.

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

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)

?

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
    return;
  }
  chan.ChatMessage(data);
}
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.
enum Bool { True, False, FileNotFound };

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

This topic is closed to new replies.

Advertisement