Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-926

IoSession IP Error when Socket Server Communicate With Microcomputer In LAN and Internet.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.0.7
    • Fix Version/s: 2.0.8
    • Component/s: Core
    • Labels:
      None
    • Environment:
      windows XP ,Eclipse 1.4.2

      Description

      A server in the LAN,Every Single Chip Microcomputer Connected by a switch.
      My Socket Server Is Runing In The Server,I Can Communicate With Every Single Chip Microcomputer
      Now,I Want My Socket Server Can Receive Data From Internet(By GPRS). a adsl modem is connected to the

      switch. the Server Can Connect to internet use PPPoE dial, At first, The Socket Server also

      can Communicate with every Single Chip Microcomputer(Include LAN and Internet). After a period of

      time,a Error is Appear,
      Some Data Come from Internet But the IOsession is A LAN IP address.
      Change a older Verion Mina(1.1.7),But the Same.
      My mina is 2.0.7.
      this is some code:

        public void messageReceived(IoSession session, Object message) throws Exception
        {
             byte[] revByteArr =(byte[])message ;
             GlobalObject.log.addNewRec(revByteArr , LogType.LOG_SYSTEM_INFO, 0, -1,        
      
      "address:"+session.getRemoteAddress());   
        }
      

      113484 INFO 2012-12-11 08:38:43 LowerComputerCommRec address:/211.140.5.116:50937 : 68 1c 06

      00 04 00 0b 01 03 00 0d 00 00 00 00 1d 08 00 01 00 00 00 00 00 07 00 00 02 00 00
      117531 INFO 2012-12-11 08:38:47 LowerComputerCommRec address:/211.140.5.116:50937 : 68 20 08

      00 04 00 84 01
      131500 INFO 2012-12-11 08:39:01 LowerComputerCommRec address:/192.168.1.226:9000 : 68 0e 0a

      00 04 00 64 01 0a 00 0d 00 00 00 00 14

      Is it a MINA bug??

        Activity

        Hide
        elecharny Emmanuel Lecharny added a comment -

        MINA does not magically transform a WAN address into a LAN address.

        You should analyze what comes into your MINA server using a protocol analyzer, like Wireshark.

        Show
        elecharny Emmanuel Lecharny added a comment - MINA does not magically transform a WAN address into a LAN address. You should analyze what comes into your MINA server using a protocol analyzer, like Wireshark.
        Hide
        sirous zlh added a comment -

        thanks Emmanuel Lecharny!

        I Difference between different devices Use IoSession。

        I Only Use setAttribute Method to remark IoSession when devices logining in socket Server。
        For example ioSession.setAttribute("deviceID", "1001");

        Then when data reveived, I can use getAttribute("deviceID") to get Device ID .

        See My code,No logging event。
        But Device ID is changed.

        Show
        sirous zlh added a comment - thanks Emmanuel Lecharny! I Difference between different devices Use IoSession。 I Only Use setAttribute Method to remark IoSession when devices logining in socket Server。 For example ioSession.setAttribute("deviceID", "1001"); Then when data reveived, I can use getAttribute("deviceID") to get Device ID . See My code,No logging event。 But Device ID is changed.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Sorry, I can't help with the snippet of code you provided. It just tells nothing about what can go wrong with your own code.

        The only valuable information is provided by session.getRemoteAddress(), which returns the IP address of the connected client.

        You provided no code to back your claim that something changed the "DeviceId" stored in an Attribute.

        To me, you obviously have something wrong in your code, but given the lack of information you are providing, I can't help.

        Show
        elecharny Emmanuel Lecharny added a comment - Sorry, I can't help with the snippet of code you provided. It just tells nothing about what can go wrong with your own code. The only valuable information is provided by session.getRemoteAddress(), which returns the IP address of the connected client. You provided no code to back your claim that something changed the "DeviceId" stored in an Attribute. To me, you obviously have something wrong in your code, but given the lack of information you are providing, I can't help.
        Hide
        sirous zlh added a comment -

        Set and Get Iosession Attribute

        public void setSocketListMap(int deviceID,IoSession ioSession)

        { GlobalObject.log.addNewRec(null, LogType.LOG_SYSTEM_INFO, 0, -1, " Reg"+deviceID+" IP:"+ioSession.getRemoteAddress()); ioSession.setAttribute("deviceID",deviceID+""); }

        public int getDeviceIDByIoSession(IoSession sc)
        {
        Object tmpobj = sc.getAttribute("deviceID");
        int deviceID = -1;
        if (null!=tmpobj)

        { deviceID = Utils.strToInt((String)tmpobj); }

        return deviceID;
        }

        Receive Data:

        public void messageReceived(IoSession session, Object message) throws Exception {
        //super.messageReceived(session, message);
        byte[] revByteArr =(byte[])message ;
        MsgBlock msgBlock = new MsgBlock(revByteArr,session);

        //get deviceID By IoSession
        int deviceID = GlobalObject.getCommLib().getDeviceIDByIoSession(session);
        GlobalObject.log.addNewRec(revByteArr , LogType.LOG_SYSTEM_INFO, 0, -1,
        "address:"+session.getRemoteAddress());
        if (deviceID==-1)

        { GlobalObject.getReceiveQueue().putMsgQueue(msgBlock); }

        else

        { GlobalObject.deviceList[deviceSN].getReceiveQueue().putMsgQueue(msgBlock); }

        }

        handle Queue

        MsgBlock currentMsgBlock = GlobalObject.getReceiveQueue().getAndDeleteMsgQueueFirst();
        (or GlobalObject.deviceList[deviceID].getReceiveQueue().getAndDeleteMsgQueueFirst())
        GlobalObject.deviceList[deviceID].getProtocolLib().analyticData(currentMsgBlock );

        handle Data

        received login code;

        xxx.xxxx.setSocketListMap(deviceID, ioSession);
        this.deviceID = ioSession;

        send Data

        public boolean sendData(byte[] byteArr, int len, int deviceID,String remark)

        { IoSession session = GlobalObject.deviceList[deviceID].getIoSession(); IoBuffer sendbuffer = Utils.byteToIoBuffer(byteArr, len); session.write(sendbuffer); }

        This is a simplified code
        No other code is associated.
        Do you doubt my code problem?
        Why is my server is running on the LAN is no problem。
        Only when there is GPRS Devices when it is wrong

        Show
        sirous zlh added a comment - Set and Get Iosession Attribute public void setSocketListMap(int deviceID,IoSession ioSession) { GlobalObject.log.addNewRec(null, LogType.LOG_SYSTEM_INFO, 0, -1, " Reg"+deviceID+" IP:"+ioSession.getRemoteAddress()); ioSession.setAttribute("deviceID",deviceID+""); } public int getDeviceIDByIoSession(IoSession sc) { Object tmpobj = sc.getAttribute("deviceID"); int deviceID = -1; if (null!=tmpobj) { deviceID = Utils.strToInt((String)tmpobj); } return deviceID; } Receive Data: public void messageReceived(IoSession session, Object message) throws Exception { //super.messageReceived(session, message); byte[] revByteArr =(byte[])message ; MsgBlock msgBlock = new MsgBlock(revByteArr,session); //get deviceID By IoSession int deviceID = GlobalObject.getCommLib().getDeviceIDByIoSession(session); GlobalObject.log.addNewRec(revByteArr , LogType.LOG_SYSTEM_INFO, 0, -1, "address:"+session.getRemoteAddress()); if (deviceID==-1) { GlobalObject.getReceiveQueue().putMsgQueue(msgBlock); } else { GlobalObject.deviceList[deviceSN].getReceiveQueue().putMsgQueue(msgBlock); } } handle Queue MsgBlock currentMsgBlock = GlobalObject.getReceiveQueue().getAndDeleteMsgQueueFirst(); (or GlobalObject.deviceList [deviceID] .getReceiveQueue().getAndDeleteMsgQueueFirst()) GlobalObject.deviceList [deviceID] .getProtocolLib().analyticData(currentMsgBlock ); handle Data received login code; xxx.xxxx.setSocketListMap(deviceID, ioSession); this.deviceID = ioSession; send Data public boolean sendData(byte[] byteArr, int len, int deviceID,String remark) { IoSession session = GlobalObject.deviceList[deviceID].getIoSession(); IoBuffer sendbuffer = Utils.byteToIoBuffer(byteArr, len); session.write(sendbuffer); } This is a simplified code No other code is associated. Do you doubt my code problem? Why is my server is running on the LAN is no problem。 Only when there is GPRS Devices when it is wrong
        Hide
        elecharny Emmanuel Lecharny added a comment -

        The code you posted does not show where the DeviceID could be changed.

        Again, check your code : use a debugger, see where the DeviceID is changed using breakpoint.

        It's 99.99% not a MINA problem, unless you can demonstrate with a sample code I can run on my computer that MINA is mis-behaving.

        Show
        elecharny Emmanuel Lecharny added a comment - The code you posted does not show where the DeviceID could be changed. Again, check your code : use a debugger, see where the DeviceID is changed using breakpoint. It's 99.99% not a MINA problem, unless you can demonstrate with a sample code I can run on my computer that MINA is mis-behaving.
        Hide
        sirous zlh added a comment -

        DeviceID can only be change by “setSocketListMap” method

        in the “setSocketListMap” method
        GlobalObject.log.addNewRec(null, LogType.LOG_SYSTEM_INFO, 0, -1, " Reg"deviceID" IP:"+ioSession.getRemoteAddress());
        can Display modified records

        but The actual data display, setSocketListMap not be used. use debugger is same.

        My code does not distinguish between Lan and Internet(GPRS), But My server is running on the LAN is no problem.
        Can't understand

        Show
        sirous zlh added a comment - DeviceID can only be change by “setSocketListMap” method in the “setSocketListMap” method GlobalObject.log.addNewRec(null, LogType.LOG_SYSTEM_INFO, 0, -1, " Reg" deviceID " IP:"+ioSession.getRemoteAddress()); can Display modified records but The actual data display, setSocketListMap not be used. use debugger is same. My code does not distinguish between Lan and Internet(GPRS), But My server is running on the LAN is no problem. Can't understand
        Hide
        elecharny Emmanuel Lecharny added a comment -

        That's plain nonsense. The setSocketListMap does NOT change the DeviceID value. It stores it.

        You are obviously missing something elswhere in your code...

        Use Wieshark to determinate what data you are receiving from the remote device, if it contains the DeviceID.

        But again, if you can't point out a problem in MINA, I can't help you. This is your code...

        Show
        elecharny Emmanuel Lecharny added a comment - That's plain nonsense. The setSocketListMap does NOT change the DeviceID value. It stores it. You are obviously missing something elswhere in your code... Use Wieshark to determinate what data you are receiving from the remote device, if it contains the DeviceID. But again, if you can't point out a problem in MINA, I can't help you. This is your code...
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Typically a user issue.

        Show
        elecharny Emmanuel Lecharny added a comment - Typically a user issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            sirous zlh
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development