使用java socket編程,發送字節數組。字節數組大小爲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();
沒有辦法:http://stackoverflow.com/a/3074427/360211 – weston