Code Monkey home page Code Monkey logo

scalaz-netty's Introduction

scalaz-netty

Build Status Gitter Chat

Some basic usage below:

import scalaz.netty._

/*
 * A simple server which accepts a connection, echos the incoming
 * data back to the sender, waiting for the client to close the connection.
 */

def log(msg: String): Task[Unit] = ???

val address = new InetSocketAddress("localhost", 9090)

val EchoServer = merge.mergeN(Netty server address map { incoming =>
  case (addr, incoming) => {
    for {
      exchange <- incoming
      _ <- Process.eval(log(s"accepted connection from $addr"))
      _ <- exchange.read to exchange.write
    } yield ()
  }
})

/*
 * A simple client which sends ByteVector(1, 2, 3) to the server,
 * prints its response and then shuts down.
 */

val DumbClient = Netty client address flatMap { exchange =>
  for {
    _ <- Process(ByteVector(1, 2, 3)) to exchange.write
    data <- exchange.read take 1
    _ <- Process.eval(log(s"received data = $data"))
  } yield ()
}

Future Work

  • Byte buffers are copied upon receipt. The only way to safely address this problem will be to integrate with Scodec and decode against the directly allocated byte buffers. Not hard to do, really...
  • Exceptions probably don't propagate properly under all circumstances.

License

Licensed under the Apache License 2.0. For more information, please see LICENSE.txt. Opening a pull request signifies your consent to license your contributions under the Apache License 2.0. Don't open a pull request if you don't know what this means.

scalaz-netty's People

Contributors

djspiewak avatar haghard avatar alissapajer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.