Пример #1
0
    public void add(NwkMessageTransaction msg, Action <NwkMessageTransaction> onCompletion)
    {
        NwkMessageListenerCouple couple = new NwkMessageListenerCouple();

        couple.onMsgReceived  += onCompletion;
        couple.originalMessage = msg;
        msgs.Add(couple);
    }
Пример #2
0
    protected override void solveTransaction(NwkMessageTransaction message, int connID)
    {
        if (message == null)
        {
            return;
        }
        log(listener.getStackCount() + " transaction(s) before solving");

        listener.solveReceivedMessage(message); // check for pongs
        log(listener.getStackCount() + " transaction(s) after solving");
        log(listener.toString());
    }
Пример #3
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);
    }
Пример #4
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);
    }
Пример #5
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);
        }
    }
Пример #6
0
    /// <summary>
    /// called by server on message received
    /// </summary>
    /// <returns>quantity of message left to process</returns>
    public int solveReceivedMessage(NwkMessageTransaction msg)
    {
        //search for transaction and remove it
        int i = 0;

        while (i < msgs.Count)
        {
            if (msgs[i].originalMessage.isSameTransaction(msg))
            {
                msgs[i].onMsgReceived(msg);
                msgs[i].clear();

                msgs.RemoveAt(i);
            }
            else
            {
                i++;
            }
        }
        return(msgs.Count);
    }
Пример #7
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();
    }
Пример #8
0
 public void clear()
 {
     onMsgReceived   = null;
     originalMessage = null;
 }
Пример #9
0
 abstract protected void solveTransaction(NwkMessageTransaction message, int connID);
Пример #10
0
 public bool isSameTransaction(NwkMessageTransaction other) => other.token == token;