
Library for building high-performance, distributed WebSocket applications
Repo obsidiandynamics/socketx, read from GitHub 15 min ago. obsidiandynamics has not joined Take My Repo.
obsidiandynamics/socketx is a public repo on GitHub by obsidiandynamics. Library for building high-performance, distributed WebSocket applications. It declares the BSD-3-Clause license on GitHub. It is written mainly in Java, has 57 stars and last changed on 2019-08-26. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-24.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Socket.xSocket.x is a library for building high-performance, distributed WebSocket applications. It provides a simple, consistent API for constructing both clients and servers, while giving you the flexibility to vary the underlying provider without changing your code.
Socket.x has been benchmarked in excess of 2 million messages/second on a 2010-era i7 quad-core CPU, using the Undertow provider. Applications built on Socket.x have demonstrated message switching at sub-millisecond latencies.
Socket.x APIs are designed around asynchronous, non-blocking and event-driven interactions. This allows you service a huge number of concurrent clients while utilising a relatively few number of OS threads. Applications built with Socket.x have achieved in excess of 1,000,000 connections per node. To put things into context, thread-bound Web servers usually top out between one and ten thousand connections.
Socket.x isn't a WebSocket implementation per se. It offers a simple, uniform API for working with a range of compliant WebSocket client/server implementations, called providers, including the industry heavy-weights Undertow and Jetty. This gives you the flexibility to adopt a provider that you're most familiar with, particularly if you require certain provider-specific features.
Having a standard API isn't just for provider portability. It gives you a clean programming model that isn't influenced by any particular provider and is generally much easier to work with. Everything's in one convenient place, well-documented and the same set of primitives are reused for both server and client parts of your application. By contrast, and we acknowledge the subjectivity of this statement, providers such as Jetty and Undertow, while being outstanding in many key areas, have evolved over numerous generational with help from a diverse group of contributors. They also typically accommodate multiple use cases - not just WebSockets, but the full breadth of the HTTP spectrum. As a result, the API is incohesive in parts, can be challenging to learn, difficult to recall and enduring to work with, and varies depending on whether you are building a server or a client. Even seemingly simple things, such as configuring SSL, requires a significant amount of reading up on. By contrast, Socket.x is designed ground-up specifically for WebSockets and asynchronous I/O, presenting a pure and uncompromised coding experience.
Socket.x builds are hosted on JCenter (Maven users may need to add the JCenter repository to their POM). Simply add the following snippet to your build file. Replace the version placeholder x.y.z in the snippet with the version shown on the Download badge at the top of this README.
For Maven:
<dependency>
<groupId>com.obsidiandynamics.socketx</groupId>
<artifactId>socketx-core</artifactId>
<version>x.y.z</version>
<type>pom</type>
</dependency>
For Gradle:
compile 'com.obsidiandynamics.socketx:socketx-core:x.y.z'
The import above only gets you the Socket.x core API. In addition, you'll need to import at least one provider. We recommend Undertow, purely due to its blistering performance and solid standards-compliance.
compile 'com.obsidiandynamics.socketx:socketx-undertow:0.1.0'
The following Java snippet demonstrates a basic client/server 'echo' app - sending a message from the client to the server and receiving a response. The complete sample code is located in examples/src/main/java/sample/echo.
XServer<?> server = UndertowServer
.factory()
.create(new XServerConfig()
.withPath("/echo")
.withPort(8080),
new XEndpointLambdaListener<>()
.onConnect(endpoint -> {
System.out.format("Server: connected %s\n", endpoint);
})
.onText((endpoint, message) -> {
System.out.format("Server: received '%s'\n", message);
endpoint.send("Hello reply from server");
}));
XClient<?> client = UndertowClient
.factory()
.create(new XClientConfig());
XEndpoint clientEndpoint = client
.connect(new URI("ws://localhost:8080/echo"),
new XEndpointLambdaListener<>()
.onConnect(endpoint -> {
System.out.format("Client: connected %s\n", endpoint);
})
.onText((endpoint, message) -> {
System.out.format("Client: received '%s'\n", message);
try {
endpoint.close();
} catch (Exception e) {
e.printStackTrace();
}
}));
clientEndpoint.send("Hello from client");
client.drain();
client.close();
server.close();
Run the example above. The output should resemble the following:
Client: connected UndertowEndpoint [remote=localhost/127.0.0.1:8080, lastActivity=2017-09-30T22:21:10.241+10:00[Australia/Sydney]]
Server: connected UndertowEndpoint [remote=/127.0.0.1:57561, lastActivity=2017-09-30T22:21:10.241+10:00[Australia/Sydney]]
Server: received 'Hello from client'
Client: received 'Hello reply from server'
The two key players in Socket.x are XServer and XClient. XServer accepts connections, while XClient lets you create outgoing connections. They must be instantiated through an XServerFactory or an XClientFactory, as appropriate; a default pair of factories is available for each supported provider. In our example, we've chosen to use UndertowServer.factory() and UndertowClient.factory(). We could've just as easily used JettyServer/JettyClient instead, without changing any other code, providing we first import socketx-jetty in our build.gradle. You can even mix JettyServer with UndertowClient; the client and server subsystems are completely independent of one another.
The next item of significance is XServerConfig and XClientConfig - a single, uniform mechanism for configuring Socket.x, irrespective of the provider. (It can also be used to pass provider-specific configuration). In our example, we're asking the server to listen on port 8080 and publish an endpoint on the /echo path. In this example, we're sticking with the default XClientConfig for our client.
When setting up a server, or when creating a new connection, one must supply an XEndpointListener implementation. This is a simple interface comprising the following self-describing methods:
void onConnect(E endpoint);
void onText(E endpoint, String message);
void onBinary(E endpoint, ByteBuffer message);
void onPing(E endpoint, ByteBuffer data);
void onPong(E endpoint, ByteBuffer data);
void onDisconnect(E endpoint, int statusCode, String reason);
void onClose(E endpoint);
void onError(E endpoint, Throwable cause);
If you favour functional programming, or need to selectively handle certain events (while ignoring others), use the XEndpointLambdaListener. Simply provide a lambda for each of the onXxx methods, using the same signature as the corresponding method in the XEndpointListener interface, as was illustrated in our earlier example. Alternatively, you can just subclass XEndpointLambdaListener directly, overriding the methods you see fit.
In our simple 'echo' example, we've provided onConnect and onText handlers, invoked when a connection is established and when a text message is received, respectively. The client opens a connection with client.connect() and sends a text message by calling send(String) on the newly opened endpoint. Upon receipt, the server echoes the message by calling send(String) on the handled endpoint. When the client receives the response, it severs the connection by calling close().
The drain() method on an XClient blocks the calling thread until the client container has no more live endpoints. (An equivalent method is also defined on XServer.) In our example this ensures that we don't prematurely clean up before the messages have gone through. (Remember, Socket.x is asynchronous - it doesn't block when sending a message.) We could've just as easily used a crude Thread.sleep(), but a drain() is much more elegant and efficient.
Calling close() on an XServer or an XClient instance will attempt to close all underlying connections, await closure, and clean up any resources - threads, sockets, byte buffers, and so forth.
Socket.x server and client providers are configured using the XServerConfig and XClientConfig objects respectively. These comprise attributes common to all providers, and can be assigned using the withXxx() chained methods. Alternatively, one can subclass the config and define these attributes in-line, using the double-brace initialization pattern, as shown in the snippet below. Beware though, as the usual caveats apply; this technique inadvertently results in an anonymous inner class, holding a reference to its enclosing object. (We're not advocating this pattern for the aforementioned reasons; we're merely stating that it's use is viable.)
new XServerConfig() {{
path = "/echo";
port = 8080;
}};
A high-water mark (HWM) acts as a hard cut-off point for the number of outstanding (queued, but not yet sent) messages on a given endpoint connection. When a connection reaches its HWM (typically through repeated unthrottled calls to send()), any new messages that would otherwise land above the high-water mark will be automatically discarded. By default, the HWM is set to Long.MAX_VALUE, which effectively means no HWM. It needs to be enabled explicitly.
A HWM can apply to both server-side and client-side endpoints. To set a HWM, follow the snippet below:
// for a server
new XServerConfig().withHighWaterMark(1000);
// or, in the case of a client
new XClientConfig().withHighWaterMark(1000);
HWMs are discussed in more detail in the context of flow control.
Often, in WebSocket applications, we need to know if the counter-party is still there. This isn't always obvious, particularly if the connection carries spurious traffic and may be idle for extended periods of time. The idle state poses another challenge - the TCP stack of either party, or an intermediary, may forcibly close the connection after a period of inactivity.
The WebSocket protocol supports layer 7 keep-alives using a pair of Ping and Pong frames. By convention, it is the responsibility of the server to send a Ping frame, which should be duly reciprocated with a Pong frame from the client.
Socket.x gives you manual control over sending Ping frames, should you require it. However, Socket.x also offers a scanner that monitors connection activity and automatically sends Pings during periods of inactivity. In addition, an idle timeout setting can be optionally assigned to terminate a connection that has been inactive for a set period of time. Only the server-side scanner will send Ping frames; however, both the server and the client containers can be configured to terminate connections due to inactivity. (The actual timeout detection and connection termination fall within the responsibilities of the underlying provider.)
The following snippet configures the server's maximum keep-alive interval and sets idle timeouts (all times are in milliseconds):
// on the server
new XServerConfig().withPingInterval(300_000).withIdleTimeout(600_000);
// on the client
new XServerConfig().withIdleTimeout(600_000);
Note: Since WebSockets are backed by TCP, the latter has a low-level mechanism for keeping connections alive (the SO_KEEPALIVE option in *NIX and Windows), which is entirely separate to the WebSockets' own Ping/Pong frames. Although you might have control over your runtime environment, and may be tempted to use TCP keep-alives, consider that you typically have little to no control over the intermediate networking infrastructure, particularly if your application communicates over the public Internet. Certain network elements, such as proxies, which are typically optimised for short-lived HTTP connections, may prematurely terminate your long-lived WebSocket connection due to inactivity. As such, it's strongly recommended that you always use the WebSocket keep-alive mechanism independently of what the underlying TCP stack is configured for. (Unless, of course, if the TCP stack uses a more aggressive setting than your WebSocket keep-alives, in which case one or the other needs to change.)
Enabling SSL (to get the wss:// protocol, which is just HTTPS behind the scenes) requires two things - selecting a HTTPS port and assigning an SSLContext. The following snippet demonstrates a simple, albeit somewhat naive SSL setup using self-signed certificates that is suitable for a development environment. The complete code listing is available at examples/src/main/java/sample/ssl.
obsidiandynamics/socketx is a public repo on GitHub by obsidiandynamics. Library for building high-performance, distributed WebSocket applications.
It declares the BSD-3-Clause license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2019-08-26. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run socketx. What is known comes from GitHub. It declares the BSD-3-Clause license on GitHub. Its last change was on 2019-08-26. It has 57 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.