Unix Domain Socket
From Wikipedia, A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system. Unix Domain Sockets leverage files and so operating system level access control can be utilized. This is a security advantage over using TCP/UDP where IPC is required without a more complex Transport Layer Security (TLS). Performance also favors Unix Domain Sockets over TCP/UDP given that the Operating System’s network stack is bypassed.
This connector provides an implementation of a Unix Domain Socket with interfaces modelled on the conventional Tcp
Akka Streams class. The connector uses JNI and so there are no native dependencies.
The binding and connecting APIs are extremely similar to the Tcp
Akka Streams class. UnixDomainSocket
is generally substitutable for Tcp
except that the SocketAddress
is different (Unix Domain Sockets requires a java.io.File
as opposed to a host and port). Please read the following for details:
Note that Unix Domain Sockets, as the name implies, do not apply to Windows.
Project Info: Alpakka Unix Domain Socket | |
---|---|
Artifact | com.lightbend.akka
akka-stream-alpakka-unix-domain-socket
1.0.2
|
JDK versions | OpenJDK 8 |
Scala versions | 2.12.7, 2.11.12, 2.13.0-M5 |
JPMS module name | akka.stream.alpakka.unixdomainsocket |
License | |
Readiness level |
Since 0.16, 2018-01-11
|
Home page | https://doc.akka.io/docs/alpakka/current/ |
API documentation | |
Forums | |
Release notes | In the documentation |
Issues | Github issues |
Sources | https://github.com/akka/alpakka |
Artifacts
- sbt
libraryDependencies += "com.lightbend.akka" %% "akka-stream-alpakka-unix-domain-socket" % "1.0.2"
- Maven
<dependency> <groupId>com.lightbend.akka</groupId> <artifactId>akka-stream-alpakka-unix-domain-socket_2.12</artifactId> <version>1.0.2</version> </dependency>
- Gradle
dependencies { compile group: 'com.lightbend.akka', name: 'akka-stream-alpakka-unix-domain-socket_2.12', version: '1.0.2' }
The table below shows direct dependencies of this module and the second tab shows all libraries it depends on transitively.
- Direct dependencies
Organization Artifact Version License com.github.jnr jffi 1.2.16 com.github.jnr jffi 1.2.17 The Apache Software License, Version 2.0 com.github.jnr jnr-unixsocket 0.22 The Apache Software License, Version 2.0 com.typesafe.akka akka-stream_2.12 2.5.22 Apache License, Version 2.0 org.scala-lang scala-library 2.12.7 BSD 3-Clause - Dependency tree
com.github.jnr jffi 1.2.17 The Apache Software License, Version 2.0 com.github.jnr jnr-unixsocket 0.22 The Apache Software License, Version 2.0 com.github.jnr jnr-constants 0.9.11 The Apache Software License, Version 2.0 com.github.jnr jnr-enxio 0.20 The Apache Software License, Version 2.0 com.github.jnr jnr-constants 0.9.11 The Apache Software License, Version 2.0 com.github.jnr jnr-ffi 2.1.9 The Apache Software License, Version 2.0 com.github.jnr jffi 1.2.17 The Apache Software License, Version 2.0 com.github.jnr jnr-a64asm 1.0.0 The Apache Software License, Version 2.0 com.github.jnr jnr-x86asm 1.0.2 MIT License org.ow2.asm asm-analysis 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-commons 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-util 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD com.github.jnr jnr-ffi 2.1.9 The Apache Software License, Version 2.0 com.github.jnr jffi 1.2.17 The Apache Software License, Version 2.0 com.github.jnr jnr-a64asm 1.0.0 The Apache Software License, Version 2.0 com.github.jnr jnr-x86asm 1.0.2 MIT License org.ow2.asm asm-analysis 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-commons 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-util 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD com.github.jnr jnr-posix 3.0.47 Eclipse Public License - v 2.0 com.github.jnr jnr-constants 0.9.11 The Apache Software License, Version 2.0 com.github.jnr jnr-ffi 2.1.9 The Apache Software License, Version 2.0 com.github.jnr jffi 1.2.17 The Apache Software License, Version 2.0 com.github.jnr jnr-a64asm 1.0.0 The Apache Software License, Version 2.0 com.github.jnr jnr-x86asm 1.0.2 MIT License org.ow2.asm asm-analysis 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-commons 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm-util 5.0.3 BSD org.ow2.asm asm-tree 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD org.ow2.asm asm 5.0.3 BSD com.typesafe.akka akka-stream_2.12 2.5.22 Apache License, Version 2.0 com.typesafe.akka akka-actor_2.12 2.5.22 Apache License, Version 2.0 com.typesafe config 1.3.3 Apache License, Version 2.0 org.scala-lang.modules scala-java8-compat_2.12 0.8.0 BSD 3-clause org.scala-lang scala-library 2.12.7 BSD 3-Clause org.scala-lang scala-library 2.12.7 BSD 3-Clause com.typesafe.akka akka-protobuf_2.12 2.5.22 Apache License, Version 2.0 org.scala-lang scala-library 2.12.7 BSD 3-Clause com.typesafe ssl-config-core_2.12 0.3.7 Apache-2.0 com.typesafe config 1.3.3 Apache License, Version 2.0 org.scala-lang.modules scala-parser-combinators_2.12 1.1.1 BSD 3-clause org.scala-lang scala-library 2.12.7 BSD 3-Clause org.scala-lang scala-library 2.12.7 BSD 3-Clause org.reactivestreams reactive-streams 1.0.2 CC0 org.scala-lang scala-library 2.12.7 BSD 3-Clause org.scala-lang scala-library 2.12.7 BSD 3-Clause
Binding to a file
- Scala
-
val file: java.io.File = // ... val binding: Future[UnixDomainSocket.ServerBinding] = UnixDomainSocket().bindAndHandle(serverSideFlow, file)
- Java
-
java.io.File file = // ... final Source<IncomingConnection, CompletionStage<ServerBinding>> connections = UnixDomainSocket.get(system).bind(file);
Connecting to a file
- Scala
-
binding.flatMap { _ => // connection val sendBytes = ByteString("Hello") Source .single(sendBytes) .via(UnixDomainSocket().outgoingConnection(file)) .runWith(Sink.ignore) }
- Java
-
connections.runForeach( connection -> { System.out.println("New connection from: " + connection.remoteAddress()); final Flow<ByteString, ByteString, NotUsed> echo = Flow.of(ByteString.class) .via( Framing.delimiter( ByteString.fromString("\n"), 256, FramingTruncation.DISALLOW)) .map(ByteString::utf8String) .map(s -> s + "!!!\n") .map(ByteString::fromString); connection.handleWith(echo, materializer); }, materializer);