0

我在两台不同的机器之间使用带有 Netty 的 NioSctpServerChannel 连接。客户端的channelActive-Handler向服务端发送一些数据后,连接建立成功并接收数据。

接收接口似乎不同于绑定接口(192.168.122.1 而不是 192.168.243.31)——这是系统问题还是网络问题?

然后通过完全不同的接口(在本例中为 virbr 192.168.122.1)发送心跳,并以破坏连接的中止作为响应。当客户端尝试发送心跳时,这在逻辑上也会以中止作为响应,因为连接已经断开。

PC1 192.168.243.31(服务器) PC2 192.168.243.12(客户端)

服务器初始化代码:

public void run() throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
                .channel(NioSctpServerChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(LogLevel.INFO))
                .option(ChannelOption.SO_KEEPALIVE, true)
                .childHandler(new ChannelInitializer<SctpChannel>() {
                    @Override
                    public void initChannel(SctpChannel ch) throws Exception {
                        ch.pipeline().addLast(new Handler1());
                        ch.pipeline().addLast(new Handler2());
                        ch.pipeline().addLast(new Handler3());
                    }
                });

        System.out.println("Connector binding...");
        ChannelFuture f = b.bind("192.168.243.31", port).sync();
        f.channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
    System.out.println("Connector ended.");
}

日志输出:

Running Staging Server ...
Connector binding...
Jul 03, 2014 8:05:27 AM io.netty.handler.logging.LoggingHandler channelRegistered
INFO: [id: 0xef4ebad6] REGISTERED
Jul 03, 2014 8:05:27 AM io.netty.handler.logging.LoggingHandler bind
INFO: [id: 0xef4ebad6] BIND: /192.168.243.31:8090
Jul 03, 2014 8:05:27 AM io.netty.handler.logging.LoggingHandler channelActive
INFO: [id: 0xef4ebad6, /192.168.243.31:8090] ACTIVE
Jul 03, 2014 8:05:33 AM io.netty.handler.logging.LoggingHandler channelRead
INFO: [id: 0xef4ebad6, /192.168.243.31:8090] RECEIVED: [id: 0x2a9c7ea3, /192.168.122.1:49423 => /192.168.243.31:8090]
HandlerActive
Data rx:
--------------------------------------------------------------------------------
      00 01 02 03  04 05 06 07  08 09 0a 0b  0c 0d 0e 0f 

0000  a8 2b 0a 31  03 32 03 16  0d 28 36                  .+.1.2...(6
--------------------------------------------------------------------------------
java.net.SocketException: Connection reset by peer
    at sun.nio.ch.sctp.SctpChannelImpl.receive0(Native Method)
    at sun.nio.ch.sctp.SctpChannelImpl.receiveIntoNativeBuffer(SctpChannelImpl.java:860)
    at sun.nio.ch.sctp.SctpChannelImpl.receive(SctpChannelImpl.java:836)
    at sun.nio.ch.sctp.SctpChannelImpl.receive(SctpChannelImpl.java:779)
    at sun.nio.ch.sctp.SctpChannelImpl.receive(SctpChannelImpl.java:741)
    at io.netty.channel.sctp.nio.NioSctpChannel.doReadMessages(NioSctpChannel.java:278)
    at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:73)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:794)
    at java.lang.Thread.run(Thread.java:745)
channelInactive

网络配置:

br1       Link encap:Ethernet  HWaddr 00:e0:7d:ae:bc:6f  
      inet addr:10.10.0.1  Bcast:10.10.255.255  Mask:255.255.0.0
      inet6 addr: fe80::2e0:7dff:feae:bc6f/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:11 errors:0 dropped:0 overruns:0 frame:0
      TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:506 (506.0 B)  TX bytes:7288 (7.2 KB)

br2       Link encap:Ethernet  HWaddr 64:31:50:3f:4e:01  
      inet addr:192.168.243.31  Bcast:192.168.243.255  Mask:255.255.255.0
      inet6 addr: fe80::6631:50ff:fe3f:4e01/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:96536 errors:0 dropped:0 overruns:0 frame:0
      TX packets:54325 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:102780133 (102.7 MB)  TX bytes:19776526 (19.7 MB)

eth0      Link encap:Ethernet  HWaddr 00:e0:7d:ae:bc:6f  
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:274 errors:0 dropped:0 overruns:0 frame:0
      TX packets:849 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:16440 (16.4 KB)  TX bytes:61267 (61.2 KB)

eth1      Link encap:Ethernet  HWaddr 64:31:50:3f:4e:01  
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:121985 errors:0 dropped:68 overruns:0 frame:0
      TX packets:60157 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:106326525 (106.3 MB)  TX bytes:20402116 (20.4 MB)
      Interrupt:19 Memory:f0100000-f0120000 

lo        Link encap:Local Loopback  
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:444 errors:0 dropped:0 overruns:0 frame:0
      TX packets:444 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:53204 (53.2 KB)  TX bytes:53204 (53.2 KB)

virbr0    Link encap:Ethernet  HWaddr 82:34:aa:4d:49:4e  
      inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
      UP BROADCAST MULTICAST  MTU:1500  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

网络流量:

1444    27.462912000    192.168.243.12  192.168.243.31  SCTP    116 INIT 
1445    27.463024000    192.168.243.31  192.168.243.12  SCTP    340 INIT_ACK 
1446    27.463030000    192.168.243.31  192.168.243.12  SCTP    340 INIT_ACK 
1447    27.463702000    192.168.243.12  192.168.243.31  SCTP    312 COOKIE_ECHO 
1448    27.463702000    192.168.243.12  192.168.243.31  SCTP    312 COOKIE_ECHO 
1449    27.463786000    192.168.243.31  192.168.243.12  SCTP    52  COOKIE_ACK 
1450    27.463798000    192.168.243.31  192.168.243.12  SCTP    52  COOKIE_ACK 
1451    27.469117000    192.168.243.12  192.168.243.31  SCTP    76  DATA 
1452    27.469117000    192.168.243.12  192.168.243.31  SCTP    76  DATA 
1453    27.469160000    192.168.243.31  192.168.243.12  SCTP    64  SACK 
1454    27.469164000    192.168.243.31  192.168.243.12  SCTP    64  SACK 
1520    30.097581000    192.168.243.31  192.168.122.1   SCTP    100 HEARTBEAT 
1521    30.097638000    192.168.122.1   192.168.243.31  SCTP    52  ABORT 
2184    59.710594000    192.168.243.12  192.168.243.31  SCTP    96  HEARTBEAT 
2185    59.710594000    192.168.243.12  192.168.243.31  SCTP    96  HEARTBEAT 
2186    59.710638000    192.168.243.31  192.168.243.12  SCTP    52  ABORT 
2187    59.710641000    192.168.243.31  192.168.243.12  SCTP    52  ABORT 1
4

1 回答 1

0

我解决了这个问题:

客户端必须绑定到特定的 IP 地址。否则,所有接口地址都在 sctp 内发送。如果每个巧合都有相同的接口 IP 地址:-( 心跳被传输到您自己的接口...

汤姆

于 2014-07-04T07:40:12.303 回答