Network

fs2.io.net.Network
See theNetwork companion object
sealed trait Network[F[_]] extends SocketGroup[F], DatagramSocketGroup[F]

Provides the ability to work with TCP, UDP, and TLS.

Attributes

Example
import fs2.Stream
import fs2.io.net.{Datagram, Network}
def send[F[_]: Network](datagram: Datagram): F[Unit] =
 Network[F].openDatagramSocket().use { socket =>
   socket.write(packet)
 }

In this example, the F[_] parameter to send requires the Network constraint instead of requiring the much more powerful Async constraint. The Network instance has a set of global resources used for managing sockets. Alternatively, use the socketGroup and datagramSocketGroup operations to manage the lifecycle of underlying resources. An instance of Network is available for any effect F which has an Async[F] instance.

Companion
object
Source
Network.scala
Graph
Supertypes
trait SocketGroup[F]
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

Returns a builder for TLSContext[F] values.

Returns a builder for TLSContext[F] values.

For example, Network[IO].tlsContext.system returns a F[TLSContext[F]].

Attributes

Source
Network.scala

Inherited methods

def client(to: SocketAddress[Host], options: List[SocketOption]): Resource[F, Socket[F]]

Opens a TCP connection to the specified server.

Opens a TCP connection to the specified server.

The connection is closed when the resource is released.

Value parameters

options

socket options to apply to the underlying socket

to

address of remote server

Attributes

Inherited from:
SocketGroup
Source
SocketGroup.scala
def datagramSocketGroup(threadFactory: ThreadFactory): Resource[F, DatagramSocketGroup[F]]

Provides an isolated DatagramSocketGroup[F] with the specified thread configuration. The resulting socket group is shutdown during resource finalization, resulting in closure of any sockets that were created.

Provides an isolated DatagramSocketGroup[F] with the specified thread configuration. The resulting socket group is shutdown during resource finalization, resulting in closure of any sockets that were created.

Note: Network is a DatagramSocketGroup so only use this operation if you need explicit control over the lifecycle of the socket group.

Value parameters

threadFactory

factory used to create selector thread

Attributes

Inherited from:
NetworkPlatform (hidden)
Source
NetworkPlatform.scala
def openDatagramSocket(address: Option[Host], port: Option[Port], options: List[DatagramSocketOption], protocolFamily: Option[ProtocolFamily]): Resource[F, DatagramSocket[F]]

Creates a UDP socket bound to the specified address.

Creates a UDP socket bound to the specified address.

Value parameters

address

address to bind to; defaults to all interfaces

options

socket options to apply to the underlying socket

port

port to bind to; defaults to an ephemeral port

protocolFamily

protocol family to use when opening the supporting DatagramChannel

Attributes

Inherited from:
DatagramSocketGroup
Source
DatagramSocketGroup.scala
def server(address: Option[Host], port: Option[Port], options: List[SocketOption]): Stream[F, Socket[F]]

Creates a TCP server bound to specified address/port and returns a stream of client sockets -- one per client that connects to the bound address/port.

Creates a TCP server bound to specified address/port and returns a stream of client sockets -- one per client that connects to the bound address/port.

When the stream terminates, all open connections will terminate as well. Because of this, make sure to handle errors in the client socket Streams.

Value parameters

address

address to accept connections from; none for all interfaces

options

socket options to apply to the underlying socket

port

port to bind

Attributes

Inherited from:
SocketGroup
Source
SocketGroup.scala
def serverResource(address: Option[Host], port: Option[Port], options: List[SocketOption]): Resource[F, (SocketAddress[IpAddress], Stream[F, Socket[F]])]

Like server but provides the SocketAddress of the bound server socket before providing accepted sockets.

Like server but provides the SocketAddress of the bound server socket before providing accepted sockets.

Make sure to handle errors in the client socket Streams.

Attributes

Inherited from:
SocketGroup
Source
SocketGroup.scala
def socketGroup(threadCount: Int, threadFactory: ThreadFactory): Resource[F, SocketGroup[F]]

Provides an isolated SocketGroup[F] with the specified thread pool configuration. The resulting socket group is shutdown during resource finalization, resulting in closure of any sockets that were created.

Provides an isolated SocketGroup[F] with the specified thread pool configuration. The resulting socket group is shutdown during resource finalization, resulting in closure of any sockets that were created.

Note: Network is a SocketGroup so only use this operation if you need explicit control over the lifecycle of the socket group.

Value parameters

threadCount

number of threads to allocate in the fixed thread pool backing the NIO channel group

threadFactory

factory used to create fixed threads

Attributes

Inherited from:
NetworkPlatform (hidden)
Source
NetworkPlatform.scala