Jump to content

  • Log In with Google      Sign In   
  • Create Account


.Net server and chat channels


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Miraz   Members   -  Reputation: 117

Like
0Likes
Like

Posted 26 March 2013 - 09:46 AM

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 :

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!
 



Sponsor:

#2 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 26 March 2013 - 10:05 AM

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.



#3 Telastyn   Crossbones+   -  Reputation: 3726

Like
0Likes
Like

Posted 26 March 2013 - 10:16 AM

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

#4 Miraz   Members   -  Reputation: 117

Like
0Likes
Like

Posted 26 March 2013 - 10:44 AM

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, 26 March 2013 - 11:04 AM.


#5 hplus0603   Moderators   -  Reputation: 5174

Like
1Likes
Like

Posted 26 March 2013 - 07:28 PM

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 };

#6 Miraz   Members   -  Reputation: 117

Like
0Likes
Like

Posted 27 March 2013 - 10:57 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS