Example #1
0
        void sendALMessage(List <int> ackList)
        {
            int            currentTimeId = conn.receiver.getCurrentTimeId();
            AckListMessage alm           = new AckListMessage(conn.connetionId, ackList, conn.receiver.lastRead, conn
                                                              .clientControl.sendRecordTable_remote, currentTimeId,
                                                              conn.connectId, conn.route.localclientId);

            alm.setDstAddress(dstIp);
            alm.setDstPort(dstPort);
            try
            {
                send(alm.getDatagramPacket());
            }
            catch (Exception e)
            {
                MLog.info(e.Message);
            }
        }
Example #2
0
        public void onReceivePacket(DatagramPacket dp)
        {
            DataMessage me;

            if (dp != null)
            {
                if (conn.isConnected())
                {
                    int ver   = MessageCheck.checkVer(dp);
                    int sType = MessageCheck.checkSType(dp);
                    if (ver == RUDPConfig.protocal_ver)
                    {
                        conn.live();
                        if (sType == MessageType.sType_DataMessage)
                        {
                            me = new DataMessage(dp);
                            int        timeId = me.getTimeId();
                            SendRecord record = conn.clientControl.sendRecordTable_remote[timeId];
                            if (record == null)
                            {
                                record = new SendRecord();
                                record.setTimeId(timeId);
                                conn.clientControl.sendRecordTable_remote.Add(timeId, record);
                            }
                            record.addSended(me.getData().Length);

                            if (timeId > currentRemoteTimeId)
                            {
                                currentRemoteTimeId = timeId;
                            }

                            int sequence = me.getSequence();

                            conn.sender.sendAckDelay(me.getSequence());
                            if (sequence > lastRead)
                            {
                                lock (availOb)
                                {
                                    receiveTable.Add(sequence, me);
                                    if (receiveTable.ContainsKey(lastRead + 1))
                                    {
                                        Monitor.Pulse(availOb);   //availOb.notify();//不知对不对
                                    }
                                }
                            }
                        }
                        else if (sType == MessageType.sType_AckListMessage)
                        {
                            AckListMessage alm       = new AckListMessage(dp);
                            int            lastRead3 = alm.getLastRead();
                            if (lastRead3 > lastRead2)
                            {
                                lastRead2 = lastRead3;
                            }
                            List <int> ackList = alm.getAckList();

                            for (int i = 0; i < ackList.Count; i++)
                            {
                                int sequence = ackList[i];
                                conn.sender.removeSended_Ack(sequence);
                            }
                            SendRecord rc1 = conn.clientControl.getSendRecord(alm.getR1());
                            if (rc1 != null)
                            {
                                if (alm.getS1() > rc1.getAckedSize())
                                {
                                    rc1.setAckedSize(alm.getS1());
                                }
                            }

                            SendRecord rc2 = conn.clientControl.getSendRecord(alm.getR2());
                            if (rc2 != null)
                            {
                                if (alm.getS2() > rc2.getAckedSize())
                                {
                                    rc2.setAckedSize(alm.getS2());
                                }
                            }

                            SendRecord rc3 = conn.clientControl.getSendRecord(alm.getR3());
                            if (rc3 != null)
                            {
                                if (alm.getS3() > rc3.getAckedSize())
                                {
                                    rc3.setAckedSize(alm.getS3());
                                }
                            }

                            if (checkWin())
                            {
                                conn.sender.play();
                            }
                        }
                        else if (sType == MessageType.sType_CloseMessage_Stream)
                        {
                            CloseMessage_Stream cm = new CloseMessage_Stream(dp);
                            reveivedClose = true;
                            int n = cm.getCloseOffset();
                            closeStream_Remote(n);
                        }
                        else if (sType == MessageType.sType_CloseMessage_Conn)
                        {
                            CloseMessage_Conn cm2 = new CloseMessage_Conn(dp);
                            conn.close_remote();
                        }
                        else
                        {
                            ////#MLog.println("未处理数据包 "+sType);
                        }
                    }
                }
            }
        }