Search Unity

How can I handle individual connections on an Asynchronous server socket

Discussion in 'Multiplayer' started by Crayz, Dec 20, 2014.

  1. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    I've decided to scratch the idea of networking within Unity to expand my knowledge a bit, and set up a standalone application (built with c#) which handles asynchronous connections and messages. From what I can tell, there's no way to handle individual connections between the server and client, so I'm trying to come up with a solution. I've compiled a library containing serialized structs and data that need to be networked between client and server, one of them being a Session struct that contains all the data of a client when connecting to a server. On my server application I plan on creating a List<NWSession> to store the data of all connecting clients, though this data isn't directly linked to the client's connection.

    Does anybody know of a way I can somehow link the connection to the list, or handle individual connections between the server and unity? Say for example I want to run a command from the server to kick a player, on the server side I know which player I want to kick by reading from List<NWSession>, but as far as I know there's no unique identifier for that client's connection to the socket.

    Some solutions I've considered are methods on the client's end to continuously check if List<NWSession> still contains his data, if not, call a disconnect method. Another idea was to network to all connected clients the data of the player being kicked, if the data matches on the client's end call a disconnect method. I'm not sure if either of these is effective or correct, but if somebody knows a solution please let me know
     
  2. Geoxion

    Geoxion

    Joined:
    May 28, 2013
    Posts:
    5
    I'm creating a muliplayer game also with C# sockets: http://pastebin.com/sMZc5C46 This is my class networkclient (at least an old version of it). Every connection is a networkclient. You can use it if you want, if it suits your game. (It's not a ready package! It's a direct copy of my code that's woven into my game)
     
    Crayz likes this.
  3. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    This snippet will be useful, thanks for posting it! After skimming through it looks setup nicely and easy to use. If I'm not mistaken GenericMessage contains values SendTime, ReceiveTime, and UniqueID while all message classes containing data that needs to be communicated (Unit position, state, etc) inherit from GenericMessage.

    Are you storing any particular data in the RequestMessage or ResponseMessage classes?