Tuna Mux

a Lightweight and High Performance Java Network Framework - Multiplexing Part

License

License

GroupId

GroupId

com.xqbase
ArtifactId

ArtifactId

tuna-mux
Last Version

Last Version

0.1.5
Release Date

Release Date

Type

Type

jar
Description

Description

Tuna Mux
a Lightweight and High Performance Java Network Framework - Multiplexing Part
Project URL

Project URL

https://github.com/xqbase/tuna
Source Code Management

Source Code Management

https://github.com/xqbase/tuna.git

Download tuna-mux

How to add to project

<!-- https://jarcasting.com/artifacts/com.xqbase/tuna-mux/ -->
<dependency>
    <groupId>com.xqbase</groupId>
    <artifactId>tuna-mux</artifactId>
    <version>0.1.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.xqbase/tuna-mux/
implementation 'com.xqbase:tuna-mux:0.1.5'
// https://jarcasting.com/artifacts/com.xqbase/tuna-mux/
implementation ("com.xqbase:tuna-mux:0.1.5")
'com.xqbase:tuna-mux:jar:0.1.5'
<dependency org="com.xqbase" name="tuna-mux" rev="0.1.5">
  <artifact name="tuna-mux" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.xqbase', module='tuna-mux', version='0.1.5')
)
libraryDependencies += "com.xqbase" % "tuna-mux" % "0.1.5"
[com.xqbase/tuna-mux "0.1.5"]

Dependencies

compile (2)

Group / Artifact Type Version
com.xqbase : tuna-core jar 0.1.5
com.xqbase : xqbase-util jar 0.2.14

test (1)

Group / Artifact Type Version
com.xqbase : tuna-misc jar 0.1.5

Project Modules

There are no modules declared in this project.

Tuna

A Lightweight and High Performance Java Network Framework with the following features:

  • High Performance and High Scalability
  • Server / Client Connections
  • Event and Filter Support
  • SSL Support
  • Non-Blocking NIO
  • Various useful components, including debug, compression, DoS filter, HTTP support, proxy, multiplex, ...
  • Single-Thread, Easy Programming

Tuna can be used as a maven dependency:

<dependency>
    <groupId>com.xqbase</groupId>
    <artifactId>tuna-core</artifactId>
    <version>0.1.1</version>
</dependency>

Here is an example to establish a broadcasting server:

import java.io.IOException;
import java.util.HashSet;

import com.xqbase.tuna.Connection;
import com.xqbase.tuna.ConnectionHandler;
import com.xqbase.tuna.ConnectionSession;
import com.xqbase.tuna.ConnectorImpl;

public class TestBroadcast {
	static final ConnectionHandler[] EMPTY_HANDLERS = {};

	public static void main(String[] args) throws IOException {
		// All connected handlers
		HashSet<ConnectionHandler> handlers = new HashSet<>();
		// Initialize a connector
		try (ConnectorImpl connector = new ConnectorImpl()) {
			connector.add(() -> {
				return new Connection() {
					ConnectionHandler handler;

					@Override
					public void setHandler(ConnectionHandler handler) {
						this.handler = handler;
					}

					@Override
					public void onRecv(byte[] b, int off, int len) {
						for (ConnectionHandler handler_ : handlers.toArray(EMPTY_HANDLERS)) {
							// "connection.onDisconnect()" might change "handlers"
							// Broadcast to all connected handlers
							handler_.send(b, off, len);
						}
					}

					@Override
					public void onConnect(ConnectionSession session) {
						handlers.add(handler);
					}

					@Override
					public void onDisconnect() {
						handlers.remove(handler);
					}
				};
			}, 23);
			// Keep the server running for 10 minutes
			connector.postDelayed(connector::interrupt, 600000);
			// "doEvents()" makes the connector working
			connector.doEvents();
		}
	}
}

Run this program and type telnet localhost in several Command Prompt windows to test it.

com.xqbase

Versions

Version
0.1.5
0.1.4
0.1.2
0.1.1
0.1.0