Skip to content

Joe0/TauNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TauNet

A super easy to use networking library.

Table of contents:

Features

  • Ease of Use - TauNet is made to be easy to use, even for beginners, as it helps enforce good programming practices by design. A lot of things are done 'magically' behind the scenes, so beginners don't need to worry about it.
  • No Explicit Bindings - TauNet uses information you're already giving it to figure out what types are bound to messages sent across the network. This gets rid of the awkward bindings that most other libraries need, as well as the shared classes. The only thing that needs to be done, is create a Subscriber that listens for the specified message, and make sure the simple name and fields match.
  • Event Driven - TauNet is event driven at the core, and requires the use of a publish-subscribe pattern.
  • Synchronous Feel - Even though TauNet is asynchronous at heart, it seems as if you're doing everything in synchronous.
  • Fast - At the core of TauNet is Netty, Feather, and Gson; all of which have been proven to be fast and reliable.

Usage

How to create a basic chat server: ```Java import com.joepritzel.feather.PSBroker; import com.joepritzel.feather.Subscriber; import com.joepritzel.taunet.Server; import com.joepritzel.taunet.ServerBuilder; import com.joepritzel.taunet.net.Send;

public class ChatServer {

public static void main(String[] args) throws Exception {
	Server  server = new ServerBuilder().build(); // Create a server.
	server.start("server"); // Start the server and give it a name.
	PSBroker broker = server.getBroker(); // Get the PSBroker for easy use.
	Subscriber<String> stringSub = new Subscriber<String>() { // Create a new subscriber, usually defined in its own class.
		@Override
		public void receive(String msg) {
			// Send the message to all active connections.
			server.getNetworkingImplementation().getConnections()
					.forEach(c -> 
						broker.publish(new Send<String>(c, msg)) // Send a message to the given client.
					);
		}
	};
	broker.subscribe(stringSub, String.class); // Register the subscriber with the PSBroker.
	server.waitForEnd(); // Wait for the server to finish executing.
}

}


An example client:
```Java
import java.util.Scanner;

import com.joepritzel.feather.Subscriber;
import com.joepritzel.taunet.Client;
import com.joepritzel.taunet.ClientBuilder;
import com.joepritzel.taunet.net.Send;

public class ChatClientExample {

	public static void main(String[] args) throws Exception {
		Client client = new ClientBuilder().build(); // Create a new client.
		Subscriber<String> stringSub = new Subscriber<String>() { // Create a new subscriber, usually defined in its own class.
			@Override
			public void receive(String msg) {
				System.out.println(msg); // Simply print out the string.
			}
		};
		client.getBroker().subscribe(stringSub, String.class); // Register the subscriber to the PSBroker.
		
		System.out.println("What is your name?"); // Ask for a username.
		try (Scanner in = new Scanner(System.in)) {
			String name = in.nextLine(); // Read in username.
			client.start(name); // Start client with the given username.
			while (true) { // Infinitely send messages that are typed in.
				client.getBroker().publish(
						new Send<String>(name + ": " + in.nextLine()));
			}
		}
	}
}

License

This project is distributed under the terms of the MIT License. See file "LICENSE" for further information.

About

A super easy and simple networking library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages