Java 插座和弹簧集成
我有一个收听端口30003的小节目。它是一个服务器类,按如下方式处理ByTestStream数据:Java 插座和弹簧集成,java,spring,sockets,port,spring-integration,Java,Spring,Sockets,Port,Spring Integration,我有一个收听端口30003的小节目。它是一个服务器类,按如下方式处理ByTestStream数据: sbsSocket = new Socket(sbsHost, sbsPort); sbsReader = new BufferedReader(new InputStreamReader(sbsSocket.getInputStream())); private void startSBSMessageReceiverThread() { new Thread(new Runnable
sbsSocket = new Socket(sbsHost, sbsPort);
sbsReader = new BufferedReader(new InputStreamReader(sbsSocket.getInputStream()));
private void startSBSMessageReceiverThread() {
new Thread(new Runnable() {
public void run() {
while(true) {
try {
String message = sbsReader.readLine();
// System.out.println(message);
tracker.handleSBSMessage(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}).start();
}
这很好用-但是我想使用Spring集成。以下是我的tcp上下文,用于实现相同的目标:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ip="http://www.springframework.org/schema/integration/ip"
xsi:schemaLocation="http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-2.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration/ip
http://www.springframework.org/schema/integration/ip/spring-integration-ip-2.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<context:component-scan base-package="com.atlaschase.falcon.integration"></context:component-scan>
<int:channel id="heathrowChannel"></int:channel>
<ip:tcp-connection-factory id="heathrowConnectionFactory" type="server" host="127.0.0.1" port="30003"/>
<ip:tcp-inbound-channel-adapter id="heathrowInboundAdapter" channel="heathrowChannel" connection-factory="heathrowConnectionFactory"/>
<int:service-activator id="adsbHandler" input-channel="heathrowChannel" ref="sbsListener"/>
</beans>
当我使用Spring集成方法启动程序时,我得到以下堆栈跟踪——告诉我套接字地址已经在使用中
SEVERE: Error on ServerSocket
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
at java.net.ServerSocket.bind(ServerSocket.java:328)
at java.net.ServerSocket.<init>(ServerSocket.java:194)
at java.net.ServerSocket.<init>(ServerSocket.java:150)
at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:163)
at org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory.run(TcpNetServerConnectionFactory.java:61)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
严重:服务器套接字上出现错误
java.net.BindException:地址已在使用中:JVM\u Bind
位于java.net.PlainSocketImpl.socketBind(本机方法)
位于java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
位于java.net.ServerSocket.bind(ServerSocket.java:328)
位于java.net.ServerSocket(ServerSocket.java:194)
位于java.net.ServerSocket。(ServerSocket.java:150)
位于javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:163)
位于org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory.run(TcpNetServerConnectionFactory.java:61)
位于java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
运行(Thread.java:662)
我不明白为什么我的标准socket程序工作得很好——为什么集成方法失败了。我的机器上有一个软件,可以在30003端口上使用数据
我希望你能帮忙
谢谢这可以通过消除服务器和客户端之间的混淆来解决。我无法生成服务器套接字,因为应用程序已绑定到该端口号 要“侦听”端口“30003”,我必须生成类型为“client”的connectionFactory:
<ip:tcp-connection-factory id="heathrowConnectionFactory" type="server" host="127.0.0.1" port="30003"/>
这可以通过消除服务器和客户端之间的混淆来解决。我无法生成服务器套接字,因为应用程序已绑定到该端口号 要“侦听”端口“30003”,我必须生成类型为“client”的connectionFactory:
<ip:tcp-connection-factory id="heathrowConnectionFactory" type="server" host="127.0.0.1" port="30003"/>
在spring上开始新的实现之前,您是否停止了在端口30003上侦听的程序?是的。有一个在30003上运行的应用程序提供了我试图监听的数据。套接字方法在该应用程序运行时可以正常工作,但此SI会产生错误。请注意,侦听端口意味着打开服务器套接字,并且不能有两个或多个应用程序打开同一端口。您的spring配置尝试打开端口30003上的ServerSocket,因此您收到的异常地址已在使用中。在spring上启动新实现之前,您是否停止了在端口30003上侦听的程序?是的。有一个在30003上运行的应用程序提供了我试图监听的数据。套接字方法在该应用程序运行时可以正常工作,但此SI会产生错误。请注意,侦听端口意味着打开服务器套接字,并且不能有两个或多个应用程序打开同一端口。您的spring配置试图打开端口30003上的ServerSocket,因此您收到的异常地址已经在使用中。