<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>x.x.x</version>
<classifier>mule-plugin</classifier>
</dependency>
Sockets Connector - Mule 4
Sockets Connector v1.1
Anypoint Connector for Sockets (Sockets Connector) provides a sockets listener, send capability, and send and receive functionality. Provides TCP and UDP requesters.
Release Notes: Sockets Connector Release Notes
Exchange: Sockets Connector
POM File Information
Mule converts RELEASE
to the latest version. To specify a version, view
Anypoint Exchange and click Dependency Snippets.
Configure a Socket Listener
The Socket Listener represents a socket endpoint that clients can connect to. By browsing to this endpoint, external clients establish a TCP Socket connection and trigger the flow each time they send a message.
You can configure a Socket Listener by referencing the configuration element from the listener’s config-ref
. This configuration sets up a Socket Listener to accept local incoming connections on port 8082:
<sockets:listener-config name="SocketsListenerConfig">
<sockets:tcp-listener-connection host="localhost" port="8082" />
</sockets:listener-config>
Supported Protocols
Sockets Connector supports these TCP protocols:
-
Direct Protocol
The socket reads until no more bytes are (immediately) available. On slow networks,EOFProtocol
andLengthProtocol
might be more reliable. -
EOF Protocol
Reading is terminated by the stream being closed by the client. -
Length Protocol
This protocol is defined by sending or reading an integer (the packet length) and then the data to be transferred. -
Custom Class Loading Length Protocol
This is a length protocol that uses a specific class loader to load objects from streams. -
Safe Protocol
This is a test protocol that should not be used in production environments. This protocol precedes every message with a cookie. -
Streaming Protocol
This protocol allows the socket’s Send operation to return a message with the originalInputStream
as payload. -
XML Message Protocol
TheXmlMessageProtocol
is a protocol used to read streaming XML documents. The only requirement is that each document includes an XML declaration at the beginning of the document of the form "<?xml…". Make sure that the XML documents being streamed begin with an XML declaration when using this protocol.
Data is read until a new document is found or until there is no more currently available data. For slower networks,XmlMessageEofProtocol
might be more reliable.
Also, because the default character encoding for the platform is used to decode the message bytes when looking for the XML declaration, some caution with message character encodings is warranted -
XML Message EOF Protocol
ExtendsXmlMessageProtocol
to continue reading until either a new message or EOF is found. -
Custom Protocol
You can define your own protocol by writing a class that extendsTcpProtocol
, and that will be used as custom protocol.
These application level protocols are implemented on top of TCP. For these protocols to work properly, implement these in both client and server ends.
By default, a socket implements Safe Protocol, but you can specify a different protocol in the config
element. The following example, demonstrates how to configure the socket to use Direct Protocol:
<sockets:listener-config name="Sockets_Listener_config" doc:name="Sockets Listener config" >
<sockets:tcp-listener-connection host="localhost" port="8082" >
<sockets:protocol>
<sockets:direct-protocol />
</sockets:protocol>
</sockets:tcp-listener-connection>
</sockets:listener-config>