JMeter-侦听给定IP上的端口

时间:2020-06-15 11:29:05

标签: websocket jmeter bind jmeter-5.0

我想运行一个jmeter测试,它监听给定ip上的端口,并打印正在发送到该端口的消息。我试过使用这个:

SocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("<client ipAddress>"),<port number>);
def server = new ServerSocket();
server.bind(inetSocketAddress);
while(true) {
    server.accept { socket ->
        log.info('Someone is connected')
        socket.withStreams { input, output ->
            def line = input.newReader().readLine()
            log.info('Received message: ' + line)
        }
        log.info("Connection processed")
    }
}

但这给了我错误-“无法分配请求的地址:JVM_Bind “

是否有其他方法可以解决此问题?还是我需要对当前的工作方式进行哪些更改?

1 个答案:

答案 0 :(得分:0)

您从正确的位置复制并粘贴了此代码,它应该可以正常工作。证据:

enter image description here

按照BindException documentation

表示尝试将套接字绑定到本地地址和端口时发生错误。通常,端口正在使用中,或者无法分配请求的本地地址。

所以我可以想到2种选择:

  1. 您的<client ipAddress>不正确,无法解决。
  2. <port number>上已经有什么东西在运行,您不能让2个应用程序监听相同的端口,第一个将成功,而另一个将失败

更多信息:

相关问题