2013-12-13 38 views
3

我想知道是否可以在spring mvc應用程序和使用TCP-IP連接的傳統系統之間插入雙向連接。如何在Spring MVC應用程序中插入TCP-IP客戶端服務器

作爲提及遺留系統與TCP/IP而不是http協作,所以不需要談論HTTP如何更好,謝謝!

+0

我不知道答案(我對'spring'不熟悉),但'遺留系統與TCP/IP協同工作,不需要HTTP,所以不需要談論HTTP如何更好「任何意義;他們不是競爭協議。 – admdrew

+0

是的但在其他答案人們說http更好等 – romu31

回答

8

參見Spring Integration。您可以使用短信網關

簡單地連線的SI流進你的MVC控制器

控制器 - >網關 - > {可選的過濾/轉換} - > TCP出站網關

網關使用其服務注入到控制器-接口。

tcp-client-server sample顯示如何。

編輯:

如果現在還不清楚從樣品,你需要定義SI流...

<!-- Client side --> 

<int:gateway id="gw" 
    service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway" 
    default-request-channel="input"/> 

<int-ip:tcp-connection-factory id="client" 
    type="client" 
    host="localhost" 
    port="1234" 
    single-use="true" 
    so-timeout="10000"/> 

<int:channel id="input" /> 

<int-ip:tcp-outbound-gateway id="outGateway" 
    request-channel="input" 
    reply-channel="clientBytes2StringChannel" 
    connection-factory="client" 
    request-timeout="10000" 
    remote-timeout="10000"/> 

<int:transformer id="clientBytes2String" 
    input-channel="clientBytes2StringChannel" 
    expression="new String(payload)"/> 

並注入網關到您的@Controller ...

public interface SimpleGateway { 

    public String send(String text); 

} 

@Controller 
public class MyController { 

     @Autowired 
     SimpleGateway gw; 

    ... 
} 
+0

謝謝,所以如果我得到它的權利網關將成爲控制器的成員? – romu31

+0

我想我的問題可能是什麼是推動TCP/IP客戶端服務器到一個春天MVC應用程序的最佳解決方案 – romu31

+0

我認爲這就是我的回答;如果從樣本中不清楚,我更新了答案。 TCP材料的完整文檔在這裏:http://docs.spring.io/spring-integration/docs/2.2.6.RELEASE/reference/html/ip.html如果你說你想讓你的控制器作爲服務器(而不是客戶端),那麼你可以使用示例的服務器端。 –

相關問題