Network
Provides the ability to work with TCP, UDP, and TLS.
- Example
- {{{
import fs2.Stream
import fs2.io.{Network, udp}
def send[F[_] : Network](packet: udp.Packet): F[Unit] =
Network[F] .udpSocketGroup.open().use { socket =>
socket.write(packet)
}
}}}
In this example, theF[_]parameter tosendrequires theNetworkconstraint instead
of requiring the much more powerfulAsync.
An instance ofNetworkis available for any effectFwhich has anAsync[F]instance. - Companion
- object
class Object
trait Matchable
class Any
Value members
Methods
Returns a TCP
SocketGroup as a resource.The
a fixed thread pool is created and used to initialize a
All network reads/writes occur on this fixed thread pool. The pool size is set to the number
of processors returned by
use
SocketGroup supports both server and client sockets. When the resource is used,a fixed thread pool is created and used to initialize a
java.nio.channels.AsynchronousChannelGroup.All network reads/writes occur on this fixed thread pool. The pool size is set to the number
of processors returned by
Runtime.getRuntime.availableProcessors. To customize this,use
tcpSocketGroupWithConfig.When the socket group is finalized, the fixed thread pool is terminated and any future reads/writes
on sockets created by the socket group will fail.
on sockets created by the socket group will fail.
def tcpSocketGroupWithConfig(nonBlockingThreadCount: Int, nonBlockingThreadFactory: ThreadFactory): Resource[F, SocketGroup[F]]
Like
tcpSocketGroup but allows configuration of the fixed size thread pool used for NIO.Returns a UDP
SocketGroup as a resource.The
When the resource is acquired, a dedicated thread is started, which
performs all non-blocking network calls. When the resource is finalized,
the thread is terminated and any sockets opened from the socket group
are closed.
SocketGroup supports both receiving and sending UDP datagrams.When the resource is acquired, a dedicated thread is started, which
performs all non-blocking network calls. When the resource is finalized,
the thread is terminated and any sockets opened from the socket group
are closed.