mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 06:00:25 +08:00
fixed bug: LogicFace.receiveInterest&Data
This commit is contained in:
@@ -5,9 +5,7 @@ import component.Identifier;
|
||||
import encoding.*;
|
||||
import mgmt.MgmtException;
|
||||
import org.junit.Test;
|
||||
import packet.Interest;
|
||||
import packet.MINPacket;
|
||||
import packet.PacketException;
|
||||
import packet.*;
|
||||
import util.ByteHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -67,7 +65,7 @@ public class LogicFaceTest {
|
||||
byte[] value={(byte)132,(byte)221,(byte)223,(byte)25};
|
||||
interest.payload.setValue(value);
|
||||
interest.congestionMark.setCongestionLevel(Long.MAX_VALUE);
|
||||
Identifier name=new Identifier("/pkusz/wefree");
|
||||
Identifier name=new Identifier("/wefree");
|
||||
interest.setName(name);
|
||||
|
||||
LogicFace face=new LogicFace();
|
||||
@@ -76,11 +74,58 @@ public class LogicFaceTest {
|
||||
|
||||
// 等待两秒钟,接收兴趣包
|
||||
try {
|
||||
Interest newInterest = face.receiveInterest(-1);
|
||||
Interest newInterest = face.receiveInterest(2000);
|
||||
System.out.println(Arrays.toString(
|
||||
new SelfEncodingBase().selfWireEncode(newInterest).getRaw()));
|
||||
}catch (Exception e){
|
||||
System.out.println("超时未收到数据:"+e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveDataByTcp() throws ComponentException, LogicFaceException, EncoderException, BlockException, MgmtException, PacketException {
|
||||
Data data=new Data();
|
||||
byte[] value={(byte)132,(byte)221,(byte)223,(byte)25};
|
||||
data.payload.setValue(value);
|
||||
data.congestionMark.setCongestionLevel(Long.MAX_VALUE);
|
||||
Identifier name=new Identifier("/wefree");
|
||||
data.setName(name);
|
||||
|
||||
LogicFace face=new LogicFace();
|
||||
face.initWithTcp("127.0.0.1",60000);
|
||||
face.sendData(data);
|
||||
|
||||
// 等待两秒钟,接收数据包
|
||||
try {
|
||||
Data data1 = face.receiveData(2000);
|
||||
System.out.println(Arrays.toString(
|
||||
new SelfEncodingBase().selfWireEncode(data1).getRaw()));
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveCPacketByTcp() throws ComponentException, LogicFaceException, EncoderException, BlockException, MgmtException, PacketException {
|
||||
CPacket cPacket=new CPacket();
|
||||
byte[] value={(byte)132,(byte)221,(byte)223,(byte)25};
|
||||
cPacket.payload.setValue(value);
|
||||
Identifier name=new Identifier("/wefree");
|
||||
Identifier nameTo=new Identifier("/wf");
|
||||
cPacket.setSrcIdentifier(name);
|
||||
cPacket.setDstIdentifier(nameTo);
|
||||
|
||||
LogicFace face=new LogicFace();
|
||||
face.initWithTcp("127.0.0.1",60000);
|
||||
face.sendCPacket(cPacket);
|
||||
|
||||
// 等待两秒钟,接收推式包
|
||||
try {
|
||||
CPacket cPacket1 = face.receiveCPacket(2000);
|
||||
System.out.println(Arrays.toString(
|
||||
new SelfEncodingBase().selfWireEncode(cPacket1).getRaw()));
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,13 +170,16 @@ public class LogicFaceTest {
|
||||
// inputStream.close();
|
||||
System.out.println(Arrays.toString(ByteHelper.getLenBytes(bytes, 0, len)));
|
||||
|
||||
// 等待三秒,再发送应答
|
||||
Thread.sleep(5000);
|
||||
|
||||
//获取向客户端发送消息的对象流
|
||||
outputStream = client.getOutputStream();
|
||||
//向客户端写数据
|
||||
outputStream.write(ByteHelper.getLenBytes(bytes, 0, len));
|
||||
System.out.println("writed to client: "+Arrays.toString(ByteHelper.getLenBytes(bytes, 0, len)));
|
||||
|
||||
Thread.sleep(20000);
|
||||
Thread.sleep(200000);
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
socket.close();
|
||||
|
||||
Reference in New Issue
Block a user