gpt4 book ai didi

spring-mvc - 如何在 Spring MVC 应用程序中插入 TCP-IP 客户端服务器

转载 作者:行者123 更新时间:2023-12-04 17:49:34 25 4
gpt4 key购买 nike

我想知道是否可以在 spring mvc 应用程序和使用 TCP-IP 连接的遗留系统之间插入双向连接。

如前所述,旧系统使用 TCP/ip 而不是 http,因此无需谈论 HTTP 更好的地方,谢谢!

最佳答案

Spring Integration .您可以使用消息传递网关简单地将 SI 流连接到 MVC Controller

Controller ->网关->{可选过滤/转换}->tcp出站网关

网关使用其服务接口(interface)注入(inject)到 Controller 中。

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)"/>

并将网关注入(inject)您的 @Controller ...
public interface SimpleGateway {

public String send(String text);

}

@Controller
public class MyController {

@Autowired
SimpleGateway gw;

...
}

关于spring-mvc - 如何在 Spring MVC 应用程序中插入 TCP-IP 客户端服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20574038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com