字节数组消息在发送时被拆分.我想一次性发送请求消息



使用java套接字编程,发送字节数组。字节数组大小为3500。它不是作为单个请求发送,而是在网络捕获时分成3个请求发送。因此服务器无法处理分割的请求。我想一次性发送请求。找到下面的代码片段,其中我用于发送字节数组请求。

        byte[] bISOMsg = new byte[9000];
        bISOMsg = isoMsg.pack();

        int messageLength = (short)bISOMsg.length;
        messageLength = messageLength - 16;
        /*  System.out.println("messageLength  -->  " + messageLength);
    System.out.println("Header  -->  " + new String(isoMsg.getHeader()));*/
        byte[] bHeaderLen = new byte[2];
        ByteBuffer bbHeader = ByteBuffer.wrap(bHeaderLen);
        bbHeader.putShort((short)messageLength);
        isoMsg.setHeader(bbHeader.array());
        bISOMsg = isoMsg.pack();
        isoMsg.unpack(bISOMsg);
        logISOMsg(isoMsg);
        System.out.println("bISOMsg....."+new String(bISOMsg));

        byte[] BitmapBytVal= new byte[32];
        System.arraycopy(bISOMsg, 4,BitmapBytVal, 0, 32);
        //System.out.println("BitmapBytVal..."+BitmapBytVal);

        ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();
        outputStream1.write(isoHeader.getBytes());
        outputStream1.write(bISOMsg, 0,4);
        outputStream1.write( HexToByte1(new String(BitmapBytVal)));
        outputStream1.write(bISOMsg, 36, bISOMsg.length-36);
        TotalMsgBytVal  =outputStream1.toByteArray();
        outputStream1.close();
        System.out.println("TotalMsgBytVal Hex value="+TotalMsgBytVal);
        System.out.println("Msg Length ---- " + TotalMsgBytVal.length);
        String msgLength= Integer.toHexString(TotalMsgBytVal.length);
        msgLength =  addZeros(msgLength,4);
        System.out.println("Msg Length ----: " + msgLength);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
        String MSGIndicater="03NPCI ONC";
        outputStream.write(MSGIndicater.getBytes());
        outputStream.write(HexToByte1(msgLength));
        outputStream.write(TotalMsgBytVal,0,TotalMsgBytVal.length);
        outputStream.close();
        TotalMsgBytVal = outputStream.toByteArray();
        Socket  soc = null;
        byte []dataRes = new byte[9000];
        System.out.println("Gateway IP Address ="+ cbsipaddr);
        System.out.println("Gateway Port ="+ cbsport);
        soc= new Socket(cbsipaddr,cbsport);
        in=soc.getInputStream();
        /*
        /* Added by Syed on 03/09/15 */
        System.out.println("Total Length of Request is = "+ TotalMsgBytVal.length);
        DataOutputStream dout = new DataOutputStream(soc.getOutputStream());
        dout.writeInt(TotalMsgBytVal.length); // write length of the message
        dout.write(TotalMsgBytVal);     // write the message
        Thread.sleep(1000);
        dout.flush();

以太网的MTU大约是1500字节。

你认为当你试图在以太网上写3500字节时会发生什么?

你的代码看起来也很奇怪,我认为你应该看看现有的实现,看看如何改进你的代码。如果它不能处理分成多个包的消息,那么它是一个相当糟糕的服务器。

最新更新