Пример #1
0
    void Start()
    {
        Application.runInBackground = true;

        // Initialization to open socket on port specified by socketId.
        NetworkTransport.Init();                                                  // init transport using default values
        ConnectionConfig config = new ConnectionConfig();                         // create connection config + channel

        channelId = config.AddChannel(QosType.Reliable);
        HostTopology topology = new HostTopology(config, maxConnections);         // create topology based on connection config

        socketId = NetworkTransport.AddHost(topology, socketPort);                // create host based on topology, listening on port 8888
        Debug.Log("Socket Open. SocketId is: " + socketId);                       // print socket ID to console

        userList    = new Dictionary <int, HashSet <MType> >();
        revUserList = new Dictionary <MType, HashSet <int> >();

        try {
            foreach (MType value in MType.GetValues(typeof(MType)))                       // initialize each message type list
            {
                revUserList.Add(value, new HashSet <int>());
            }
        } catch (ArgumentException) {
            Debug.Log("Tried to add duplicate message type to revUserList!");
        }
    }