Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Asynchronus Socket please help

Back to Forum: Tech Off
  • User profile image

    I have a server that can talk to many clients, and in an asynchronus way, i want to identify what message game from which client, and also to send a message to a specific client

    I am reading that people use ArrayList, but how do i do it?  can i add Socket : and the UserID GUID in the ArrayList for example?

    and then later, i loop through an arraylist and search for the socket assoicated wiht the UserID GUID

    is that how i should do it? or what?
    also what are dictionary classes used for, and are they better than ArrayLists in my kind of task that i am trying to do?


  • User profile image

    See Mister E's post in the DotNet Forums thread

    while (true)
        // sit in blocking mode and wait for a client to connect
        Socket socketForClient = tcpListener.AcceptSocket();
        // a client has connected and has been issued a socket
        if (socketForClient.Connected)
            // connection made, socket issued...
            // do whatever with the new socket
            // e.g. hand it off to another class
                             ChatSession s = new ChatSession(socketForClient);
        // time to go back to listening for new connections

  • User profile image

    while (true)

    what is the definition of true here?

    what is true? and when does it get false?

    while (x ==true)

    what is x?

    I am using Async sockets, not the TCPClient and TCPListeners,

    I have a new connection set up with all the callback methods,

    but now i want to know once a client is connected, how do i tag it with the UserID in an array list?

    i made a stateobject, in it there is SocketUserID

    would that be sufficinet, i add the socket to an arraylist after the logon packet is recived

    i have a function that takes the UserID and gives me the Socket Index in the arraylist,

    is there a better way?

  • User profile image

    also, how do i know if a client disconnected?

    i have this way, if the connection got reset by the peer, then an exception with error number e.ErrorCode == 10054, that would mean the peer has disconnected..

    is there another better way?

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.