1

ポート 30003 をリッスンする小さなプログラムがあります。これは、バイトストリーム データを次のように処理するサーバー クラスです。

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 Integration の使用に移行したいと考えています。これは、同じことを達成するための私の tcp-context です。

<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 Integration アプローチを使用してプログラムを開始すると、次のスタック トレースが表示され、ソケット アドレスが既に使用されていることがわかります。

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)

標準のソケット プログラムが正常に動作するのに、なぜ統合アプローチが失敗するのか理解できません。私のマシンには、30003 ポートでデータを利用できるようにするソフトウェアが少しあります。

お役に立てれば幸いです。

ありがとう

4

1 に答える 1

1

これは、サーバーとクライアントの間の混乱を解消することで解決されます。アプリケーションがすでにそのポート番号にバインドされているため、サーバー ソケットを生成できませんでした。

ポート「30003」を「リッスン」するには、「クライアント」タイプの connectionFactory を生成する必要がありました。

<ip:tcp-connection-factory id="heathrowConnectionFactory" type="server" host="127.0.0.1" port="30003"/>
于 2012-04-18T11:49:08.910 に答える