membersound
membersound

Reputation: 86905

How to connect a client to multiple server sockets?

I'm using spring-integration to connect a client to a server socket using the following components:

DirectChannel
TcpConnectionFactoryFactoryBean
TcpOutboundGateway
@MessagingGateway

Problem: the TcpConnectionFactoryFactoryBean is tied to a specific socket port. I'd like to connect the client to multiple server sockets.

How could I achieve this? Is that possible at all?

Upvotes: 3

Views: 1596

Answers (2)

Gary Russell
Gary Russell

Reputation: 174759

Correct. You need a separate connection factory for each server/port.

There's not currently any mechanism in Spring Integration to dynamically select a TCP host/port for each message.

Such a mechanism would probably need to cache connections to avoid having to open a new socket for each request. Feel free to open a new feature JIRA issue and we'll consider it for a future release.

Upvotes: 1

Timo Hanisch
Timo Hanisch

Reputation: 224

A TCP connection is bound to following parameters:

  • Source address
  • Source port
  • Remote address
  • Remote port

I think it's not intended to offer the possibilty to create one to many connections via one socket since this would be against the TCP definition.

Wiki-Article for TCP

So the solution would be to create multiple sockets, each holding one connection to a different server.

Upvotes: 3

Related Questions