Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 729 Bytes

README.md

File metadata and controls

31 lines (25 loc) · 729 Bytes

saio

AIO library for scala

Quick example

import io.github.free.lock.saio.{ AIO, ConnectionHandler, AIOConnection }
import java.net.InetSocketAddress
import scala.concurrent.ExecutionContext.Implicits.global

val server = AIO.getTcpServer(
  onConnection = (connection: AIOConnection.Connection) => {
    ConnectionHandler(
      connection,
      onData = (data: Array[Byte]) => {
        val text = new String(data, "UTF-8")
        println(s"recieved data: ${text}") 
      }
    )
  }
)

val port = server.getLocalAddress().asInstanceOf[InetSocketAddress].getPort()

AIO.getTcpClient(port = port) map {
  conn =>
    val connHandler = ConnectionHandler(conn)
    connHandler.sendMessage("hello world!")
}