调试udp channel,失败

This commit is contained in:
free will
2021-10-25 17:08:23 +08:00
parent aaf5ef58ed
commit e71261132d
2 changed files with 7 additions and 2 deletions
+5 -2
View File
@@ -12,6 +12,7 @@ import security.KeyChain;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
@@ -84,11 +85,13 @@ public class LogicFace {
*/
public boolean initWithUdp(String ip,Integer port) throws LogicFaceException {
try {
//
SocketAddress sa=new InetSocketAddress(ip, port);
// Transport
DatagramChannel channel=DatagramChannel.open();
channel.connect(new InetSocketAddress(ip, port));
channel.connect(sa);
UdpTransport udpTransport=new UdpTransport();
udpTransport.init(channel,new InetSocketAddress(ip, port));
udpTransport.init(channel,sa);
// LinkService
this.linkService=new LinkService();
@@ -39,11 +39,13 @@ public class UdpTransport extends Transport implements ITransport{
this.channel=channel;
this.localAddr=channel.getLocalAddress().toString();
this.localUri="udp://"+this.localAddr;
System.out.println("lu: "+this.localUri);
this.remoteAddr=remoteUdpAddr.toString();
this.remoteUri="udp://"+this.remoteAddr;
this.recvBuf=new byte[9000];
this.remoteUdpAddr=remoteUdpAddr;
System.out.println("ru: "+this.remoteUri);
} catch (IOException e) {
throw new LogicFaceException("UdpTransport.init: "+e.getMessage());
}