Skip to content
/ Blue Public

An asynchronous networking library that just works

License

Notifications You must be signed in to change notification settings

shakram02/Blue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blue

Build Status

An asynchronous networking library that just works

How to Use

You can check out the test directory for full use cases

Create a server

Setup event handlers for the server then start it providing the IP and Port

val server = BlueServer()
server.onConnected += { ch -> 
    System.err.println("Client connected")
    ch.channel.write(ByteBuffer.wrap("Hello!")).get() 
    }


server.onReceived += { receivedEventArgs ->
    serverRead += receivedEventArgs.bytes.size
    received = String(receivedEventArgs.bytes)
    println("Server received:$received")
    }

server.start("localhost", 60001)

Connect a client

Connect to a server using IP and Port then send messages

val client = BlueClient()

// Register for events
client.onConnected += { /* Your code here */ }
client.onReceived += { b:ByteArray -> /*your code here*/ }

// Simple usage
client.connect("localhost", 6001)
client.send("Hello World!".toByteArray())