Esempio n. 1
0
    /// <summary>
    /// SERVER
    /// server -> send -> client
    /// </summary>
    public void sendTransaction(NwkMessageTransaction message, int clientConnectionId, Action <NwkMessageTransaction> onTransactionCompleted = null)
    {
        message.getIdCard().setMessageSender(0); // server is sender
        message.generateToken();                 // won't change token if already setup, a token for when the answer arrives

        Debug.Assert(message.getMessageUnetId() == NwkMessageTransaction.MSG_ID_TRANSACTION, "trying to send transaction message with a message that is not a transaction message ; " + message.getMessageUnetId() + " vs " + NwkMessageTransaction.MSG_ID_TRANSACTION);
        Debug.Assert(message.getIdCard().getMessageType() >= 0, "message type is not setup ?");
        Debug.Assert(message.token >= 0, "token is not setup");

        NwkSystemBase.nwkSys.log("sending transaction (" + message.getMessageUnetId() + ") token ? " + message.token + " type ? " + message.getIdCard().getMessageType());

        NetworkServer.SendToClient(clientConnectionId, message.getMessageUnetId(), message);
        NwkMessageListener.getListener().add(message, onTransactionCompleted);
    }
Esempio n. 2
0
    override protected void solveTransaction(NwkMessageTransaction message, int connID)
    {
        log("solving transaction : " + message.getIdCard().toString() + " => " + message.token);

        eNwkMessageType mtype = (eNwkMessageType)message.getIdCard().getMessageType();

        switch (mtype)
        {
        case eNwkMessageType.CONNECTION_PINGPONG: // received msg from server that is asking for uid
            solvePingPong(message);
            break;

        case eNwkMessageType.NONE: break;

        default: throw new NotImplementedException("transaction not implem " + mtype);
        }
    }
Esempio n. 3
0
    void solvePingPong(NwkMessageTransaction message)
    {
        NwkMessageTransaction trans = new NwkMessageTransaction();
        //msg.clean();

        NwkMessageTransaction original = message as NwkMessageTransaction;

        trans.getIdCard().setupId(nwkUid, (int)eNwkMessageType.CONNECTION_PINGPONG); // same type for transaction solving

        trans.token = original.token;                                                // transfert token

        log("server asked for pong, processing ; token : " + trans.token);

        sendWrapperClient.sendClientToServer(trans);
    }
Esempio n. 4
0
    void OnClientConnected(NetworkMessage clientConnectionMessage)
    {
        log("OnClientConnected ; sending ping pong transaction");

        //server prepare message to ask for uid of newly connected client
        //to send only to new client server will use connectionId stored within origin conn message
        NwkMessageTransaction transMessage = new NwkMessageTransaction();

        transMessage.getIdCard().setupId(0, (int)eNwkMessageType.CONNECTION_PINGPONG);

        //give message to listener system to plug a callback
        sendWrapper.sendTransaction(transMessage, clientConnectionMessage.conn.connectionId, delegate(NwkMessageTransaction waybackMessage)
        {
            // --- CALLBACK TRANSACTION

            log("received uid from client : " + waybackMessage.getIdCard().getMessageSender() + " , token ? " + waybackMessage.token);

            NwkClientData data = addClient(waybackMessage.getIdCard().getMessageSender(), clientConnectionMessage.conn.connectionId); // server ref new client in list
            data.setConnected();                                                                                                      // mark as connected

            //broadcast to all
            NwkMessageFull msg = new NwkMessageFull();
            msg.getIdCard().setupId(0, (int)eNwkMessageType.CONNECTION);

            msg.header.setupHeader(waybackMessage.getIdCard().getMessageSender().ToString()); // msg will contain new client uid

            //send new client UID to everybody
            sendWrapper.broadcastServerToAll(msg, 0);

            // ---
        });

        //log("asking to new client its uid");

        //NwkUiView nView = qh.gc<NwkUiView>();
        //if (nView != null) nView.onConnection();
    }