sealed trait Network[F[_]] extends SocketGroup[F] with DatagramSocketGroup[F]
Provides the ability to work with TCP, UDP, and TLS.
- Source
- Network.scala
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 tosendrequires theNetworkconstraint instead of requiring the much more powerfulAsyncconstraint. TheNetworkinstance has a set of global resources used for managing sockets. Alternatively, use thesocketGroupanddatagramSocketGroupoperations to manage the lifecycle of underlying resources. An instance ofNetworkis available for any effectFwhich has anAsync[F]instance.
- Alphabetic
- By Inheritance
- Network
- DatagramSocketGroup
- SocketGroup
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
client(to: SocketAddress[Host], options: List[SocketOption] = List.empty): 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.
- to
address of remote server
- options
socket options to apply to the underlying socket
- Definition Classes
- SocketGroup
-
abstract
def
datagramSocketGroup(threadFactory: ThreadFactory = ...): Resource[F, DatagramSocketGroup[F]]
Provides an isolated
DatagramSocketGroup[F]with the specified thread configuration.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:
Networkis aDatagramSocketGroupso only use this operation if you need explicit control over the lifecycle of the socket group.- threadFactory
factory used to create selector thread
-
abstract
def
openDatagramSocket(address: Option[Host] = None, port: Option[Port] = None, options: List[SocketOption] = Nil, protocolFamily: Option[ProtocolFamily] = None): Resource[F, DatagramSocket[F]]
Creates a UDP socket bound to the specified address.
Creates a UDP socket bound to the specified address.
- address
address to bind to; defaults to all interfaces
- port
port to bind to; defaults to an ephemeral port
- options
socket options to apply to the underlying socket
- protocolFamily
protocol family to use when opening the supporting
DatagramChannel
- Definition Classes
- DatagramSocketGroup
-
abstract
def
server(address: Option[Host] = None, port: Option[Port] = None, options: List[SocketOption] = List.empty): 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.
- address
address to accept connections from; none for all interfaces
- port
port to bind
- options
socket options to apply to the underlying socket
- Definition Classes
- SocketGroup
-
abstract
def
serverResource(address: Option[Host] = None, port: Option[Port] = None, options: List[SocketOption] = List.empty): Resource[F, (SocketAddress[IpAddress], Stream[F, Socket[F]])]
Like server but provides the
SocketAddressof the bound server socket before providing accepted sockets.Like server but provides the
SocketAddressof the bound server socket before providing accepted sockets.- Definition Classes
- SocketGroup
-
abstract
def
socketGroup(threadCount: Int = 1, threadFactory: ThreadFactory = ...): Resource[F, SocketGroup[F]]
Provides an isolated
SocketGroup[F]with the specified thread pool configuration.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:
Networkis aSocketGroupso only use this operation if you need explicit control over the lifecycle of the socket group.- threadCount
number of threads to allocate in the fixed thread pool backing the NIO channel group
- threadFactory
factory used to create fixed threads
-
abstract
def
tlsContext: Builder[F]
Returns a builder for
TLSContext[F]values.Returns a builder for
TLSContext[F]values.For example,
Network[IO].tlsContext.systemreturns aF[TLSContext[F]].
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated