Java源码示例:net.fs.rudp.message.DataMessage
示例1
public void reSend(int sequence,int count){
if(sendTable.containsKey(sequence)){
DataMessage dm=sendTable.get(sequence);
if(dm!=null){
sendDataMessage(dm,true,false,true);
}
}
}
示例2
public void reSend(int sequence,int count){
if(sendTable.containsKey(sequence)){
DataMessage dm=sendTable.get(sequence);
if(dm!=null){
sendDataMessage(dm,true,false,true);
}
}
}
示例3
public void reSend(int sequence, int count) {
if (sendTable.containsKey(sequence)) {
DataMessage dm = sendTable.get(sequence);
if (dm != null) {
sendDataMessage(dm, true, false, true);
}
}
}
示例4
void sendNata(byte[] data,int offset,int length) throws ConnectException, InterruptedException{
if(!closed){
if(!streamClosed){
DataMessage me=new DataMessage(sequence,data,0,(short) length,conn.connectId,conn.route.localclientId);
me.setDstAddress(dstIp);
me.setDstPort(dstPort);
synchronized (syn_send_table) {
sendTable.put(me.getSequence(),me);
}
synchronized (winOb){
if(!conn.receiver.checkWin()){
try {
winOb.wait();
} catch (InterruptedException e) {
throw e;
}
}
}
boolean twice=false;
if(RUDPConfig.twice_tcp){
twice=true;
}
if(RUDPConfig.double_send_start){
if(me.getSequence()<=5){
twice=true;
}
}
sendDataMessage(me,false,twice,true);
lastSendTime=System.currentTimeMillis();
sendOffset++;
s+=me.getData().length;
conn.clientControl.resendMange.addTask(conn, sequence);
sequence++;//必须放最后
}else{
throw new ConnectException("RDP连接已断开sendData");
}
}else{
throw new ConnectException("RDP连接已经关闭");
}
}
示例5
void sendDataMessage(DataMessage me,boolean resend,boolean twice,boolean block){
synchronized (conn.clientControl.getSynlock()) {
long startTime=System.nanoTime();
long t1=System.currentTimeMillis();
conn.clientControl.onSendDataPacket(conn);
int timeId=conn.clientControl.getCurrentTimeId();
me.create(timeId);
SendRecord record_current=conn.clientControl.getSendRecord(timeId);
if(!resend){
//第一次发,修改当前时间记录
me.setFirstSendTimeId(timeId);
me.setFirstSendTime(System.currentTimeMillis());
record_current.addSended_First(me.getData().length);
record_current.addSended(me.getData().length);
}else {
//重发,修改第一次发送时间记录
SendRecord record=conn.clientControl.getSendRecord(me.getFirstSendTimeId());
record.addResended(me.getData().length);
record_current.addSended(me.getData().length);
}
try {
sendSum++;
sum++;
unAckMax++;
long t=System.currentTimeMillis();
send(me.getDatagramPacket());
if(twice){
send(me.getDatagramPacket());//发两次
}
if(block){
conn.clientControl.sendSleep(startTime, me.getData().length);
}
TrafficEvent event=new TrafficEvent("",ran.nextLong(),me.getData().length,TrafficEvent.type_uploadTraffic);
Route.fireEvent(event);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例6
DataMessage getDataMessage(int sequence){
return sendTable.get(sequence);
}
示例7
void removeSended_Ack(int sequence){
synchronized (syn_send_table) {
DataMessage dm=sendTable.remove(sequence);
}
}
示例8
public byte[] receive() throws ConnectException {
DataMessage me=null;
if(conn.isConnected()){
me=receiveTable.get(lastRead+1);
synchronized (availOb){
if(me==null){
//MLog.println("等待中 "+conn.connectId+" "+(lastRead+1));
try {
availOb.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
me=receiveTable.get(lastRead+1);
//MLog.println("等待完成aaa "+conn.connectId+" "+(lastRead+1));
}
}
}else{
//throw new ConnectException("连接未建立");
throw new ConnectException("");
}
if(!streamClose){
checkCloseOffset_Remote();
if(me==null){
//throw new ConnectException("连接已断开");
throw new ConnectException("");
}else {
}
conn.sender.sendLastReadDelay();
lastRead++;
synchronized (availOb){
receiveTable.remove(me.getSequence());
}
received+=me.getData().length;
//System.out.println("received "+received/1024/1024+"MB");
return me.getData();
}else{
//throw new ConnectException("连接已断开");
throw new ConnectException("");
}
}
示例9
void sendNata(byte[] data,int offset,int length) throws ConnectException, InterruptedException{
if(!closed){
if(!streamClosed){
DataMessage me=new DataMessage(sequence,data,0,(short) length,conn.connectId,conn.route.localclientId);
me.setDstAddress(dstIp);
me.setDstPort(dstPort);
synchronized (syn_send_table) {
sendTable.put(me.getSequence(),me);
}
synchronized (winOb){
if(!conn.receiver.checkWin()){
try {
winOb.wait();
} catch (InterruptedException e) {
throw e;
}
}
}
boolean twice=false;
if(RUDPConfig.twice_tcp){
twice=true;
}
if(RUDPConfig.double_send_start){
if(me.getSequence()<=5){
twice=true;
}
}
sendDataMessage(me,false,twice,true);
lastSendTime=System.currentTimeMillis();
sendOffset++;
s+=me.getData().length;
conn.clientControl.resendMange.addTask(conn, sequence);
sequence++;//必须放最后
}else{
throw new ConnectException("RDP连接已断开sendData");
}
}else{
throw new ConnectException("RDP连接已经关闭");
}
}
示例10
void sendDataMessage(DataMessage me,boolean resend,boolean twice,boolean block){
synchronized (conn.clientControl.getSynlock()) {
long startTime=System.nanoTime();
long t1=System.currentTimeMillis();
conn.clientControl.onSendDataPacket(conn);
int timeId=conn.clientControl.getCurrentTimeId();
me.create(timeId);
SendRecord record_current=conn.clientControl.getSendRecord(timeId);
if(!resend){
//第一次发,修改当前时间记录
me.setFirstSendTimeId(timeId);
me.setFirstSendTime(System.currentTimeMillis());
record_current.addSended_First(me.getData().length);
record_current.addSended(me.getData().length);
}else {
//重发,修改第一次发送时间记录
SendRecord record=conn.clientControl.getSendRecord(me.getFirstSendTimeId());
record.addResended(me.getData().length);
record_current.addSended(me.getData().length);
}
try {
sendSum++;
sum++;
unAckMax++;
long t=System.currentTimeMillis();
send(me.getDatagramPacket());
if(twice){
send(me.getDatagramPacket());//发两次
}
if(block){
conn.clientControl.sendSleep(startTime, me.getData().length);
}
TrafficEvent event=new TrafficEvent("",ran.nextLong(),me.getData().length,TrafficEvent.type_uploadTraffic);
Route.fireEvent(event);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例11
DataMessage getDataMessage(int sequence){
return sendTable.get(sequence);
}
示例12
void removeSended_Ack(int sequence){
synchronized (syn_send_table) {
DataMessage dm=sendTable.remove(sequence);
}
}
示例13
public byte[] receive() throws ConnectException {
DataMessage me=null;
if(conn.isConnected()){
me=receiveTable.get(lastRead+1);
synchronized (availOb){
if(me==null){
//MLog.println("等待中 "+conn.connectId+" "+(lastRead+1));
try {
availOb.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
me=receiveTable.get(lastRead+1);
//MLog.println("等待完成aaa "+conn.connectId+" "+(lastRead+1));
}
}
}else{
throw new ConnectException("连接未建立");
}
if(!streamClose){
checkCloseOffset_Remote();
if(me==null){
throw new ConnectException("连接已断开ccccccc");
}else {
}
conn.sender.sendLastReadDelay();
lastRead++;
synchronized (availOb){
receiveTable.remove(me.getSequence());
}
received+=me.getData().length;
//System.out.println("received "+received/1024/1024+"MB");
return me.getData();
}else{
throw new ConnectException("连接已断开");
}
}
示例14
void sendNata(byte[] data, int offset, int length) throws ConnectException, InterruptedException {
if (!closed) {
if (!streamClosed) {
DataMessage me = new DataMessage(sequence, data, 0, (short) length, conn.connectId, conn.route
.localclientId);
me.setDstAddress(dstIp);
me.setDstPort(dstPort);
synchronized (syn_send_table) {
sendTable.put(me.getSequence(), me);
}
synchronized (winOb) {
if (!conn.receiver.checkWin()) {
winOb.wait();
}
}
boolean twice = false;
if (RUDPConfig.twice_tcp) {
twice = true;
}
if (RUDPConfig.double_send_start) {
if (me.getSequence() <= 5) {
twice = true;
}
}
sendDataMessage(me, false, twice, true);
lastSendTime = System.currentTimeMillis();
sendOffset++;
s += me.getData().length;
conn.clientControl.resendMange.addTask(conn, sequence);
sequence++;//必须放最后
} else {
throw new ConnectException("RDP连接已断开sendData");
}
} else {
throw new ConnectException("RDP连接已经关闭");
}
}
示例15
void sendDataMessage(DataMessage me, boolean resend, boolean twice, boolean block) {
synchronized (conn.clientControl.getSynlock()) {
long startTime = System.nanoTime();
long t1 = System.currentTimeMillis();
conn.clientControl.onSendDataPacket(conn);
int timeId = conn.clientControl.getCurrentTimeId();
me.create(timeId);
SendRecord record_current = conn.clientControl.getSendRecord(timeId);
if (!resend) {
//第一次发,修改当前时间记录
me.setFirstSendTimeId(timeId);
me.setFirstSendTime(System.currentTimeMillis());
record_current.addSended_First(me.getData().length);
record_current.addSended(me.getData().length);
} else {
//重发,修改第一次发送时间记录
SendRecord record = conn.clientControl.getSendRecord(me.getFirstSendTimeId());
record.addResended(me.getData().length);
record_current.addSended(me.getData().length);
}
try {
sendSum++;
sum++;
unAckMax++;
long t = System.currentTimeMillis();
send(me.getDatagramPacket());
if (twice) {
send(me.getDatagramPacket());//发两次
}
if (block) {
conn.clientControl.sendSleep(startTime, me.getData().length);
}
TrafficEvent event = new TrafficEvent("", ran.nextLong(), me.getData().length, TrafficEvent
.type_uploadTraffic);
Route.fireEvent(event);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例16
DataMessage getDataMessage(int sequence) {
return sendTable.get(sequence);
}
示例17
public byte[] receive() throws ConnectException {
DataMessage me;
if (conn.isConnected()) {
me = receiveTable.get(lastRead + 1);
synchronized (availOb) {
if (me == null) {
//MLog.println("等待中 "+conn.connectId+" "+(lastRead+1));
try {
availOb.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
me = receiveTable.get(lastRead + 1);
//MLog.println("等待完成aaa "+conn.connectId+" "+(lastRead+1));
}
}
} else {
throw new ConnectException("连接未建立");
}
if (!streamClose) {
checkCloseOffset_Remote();
if (me == null) {
throw new ConnectException("连接已断开ccccccc");
}
conn.sender.sendLastReadDelay();
lastRead++;
synchronized (availOb) {
receiveTable.remove(me.getSequence());
}
received += me.getData().length;
//System.out.println("received "+received/1024/1024+"MB");
return me.getData();
} else {
throw new ConnectException("连接已断开");
}
}