Ejemplo n.º 1
0
    public void init()
    {
        // protocol init
        NetworkTransport.Init();
        ServerNET_RecieaveFunction.init(this);
        ServerNET_SendFunction.init(this);

        ConnectionConfig cc = new ConnectionConfig();

        reliableChanel   = cc.AddChannel(QosType.Reliable); // ReliableSequenced, Reliable
        unReliableChanel = cc.AddChannel(QosType.Unreliable);

        HostTopology topo = new HostTopology(cc, MAX_USER);

        // server socket
        hostId    = NetworkTransport.AddHost(topo, PORT, null);
        isStarted = true;

        Debug.Log("opening connection on port:" + PORT + ".");
    }
Ejemplo n.º 2
0
    public void UpdateMessagePump()
    {
        if (!isStarted)
        {
            return;
        }

        recvBuffer = new byte[BUFFER_SIZE];

        networkEvntType = NetworkTransport.Receive(out recieavedHostID, out connectionId, out chanelId, recvBuffer, BUFFER_SIZE, out DataSize, out error);
        switch (networkEvntType)
        {
        case NetworkEventType.Nothing:
            break;

        case NetworkEventType.ConnectEvent:
            OnClientConnect(connectionId);

            Debug.Log("user " + connectionId + " connected.");
            break;

        case NetworkEventType.DisconnectEvent:
            OnClientDisconnect(connectionId);

            Debug.Log("user " + connectionId + " disconnected.");
            break;

        case NetworkEventType.DataEvent:
            // Debug.Log("recieaved from: " + connectionId + " | data type: " + recvBuffer[0]);
            ServerNET_RecieaveFunction.OnDataRecieaved(recvBuffer);
            break;

        default:
        case NetworkEventType.BroadcastEvent:
            Debug.Log("unexpected network event type.");
            break;
        }
    }