Networking help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Networking help

  1. #1
    Join Date
    Nov 2009
    Posts
    29

    Networking help

    I am trying to add a simple Private message type system to a chat client in order to par up to users to play a game. The way I am sending the first request to the server is sending a message with a prefix + username of the person you want to play with. The server catches and then removes the prefix to get the username.

    it uses 2 hashtables for the uernames and there connection.

    Code:
    // This hash table stores users and connections (browsable by user)
    public static Hashtable htUsers = new Hashtable(30); // 30 users at one time limit
    
    // This hash table stores connections and users (browsable by connection)
    public static Hashtable htConnections = new Hashtable(30); // 30 users at one time limit
    it uses

    Code:
    swSenderSender = new StreamWriter(tcpClients[i].GetStream());
    to send a message to each person where i is a int in a for loop where it ranges from 0 to the number of connections.

    How can I make this so I can send a message back to the username specify in the incoming message?

    example:

    there are 3 users online.

    User1 = "Bob";
    User2 = "Smith";
    User3 = "Joe";

    now user1 clicks on a username in the listbox of all online users and then the button to initiate the game.

    He clicked on Smith so the message is sent as "5|Smith"

    now on the server side, it has Bob as the sender, it catches the "5|" prefix and removes it and now the string message is "Smith"

    This is where im stuck, how can i get the address to use with

    Code:
    swSenderSender = new StreamWriter(tcpClients[i].GetStream());
    based on the username name stored in the hastables.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Networking help

    use 1 Dictionary instead of 2 Hashtables
    Code:
    Dictionary<string, TcpClient> Users = new Dictionary<string, TcpClient>();
    
    TcpClient client = Users["Smith"];

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center