Initial commit
This commit is contained in:
parent
81a0e108ab
commit
3a44c2b3ae
5 changed files with 204 additions and 0 deletions
81
.gitignore
vendored
Normal file
81
.gitignore
vendored
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
## File-based project format:
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
**/.idea
|
||||||
|
|
||||||
|
## Plugin-specific files:
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
|
||||||
|
# ---> Java
|
||||||
|
*.class
|
||||||
|
|
||||||
|
*/target/*
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
# ---> SublimeText
|
||||||
|
# cache files for sublime text
|
||||||
|
*.tmlanguage.cache
|
||||||
|
*.tmPreferences.cache
|
||||||
|
*.stTheme.cache
|
||||||
|
|
||||||
|
# workspace files are user-specific
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
|
# project files should be checked into the repository, unless a significant
|
||||||
|
# proportion of contributors will probably not be using SublimeText
|
||||||
|
# *.sublime-project
|
||||||
|
|
||||||
|
# sftp configuration file
|
||||||
|
sftp-config.json
|
||||||
|
|
||||||
|
# ---> macOS
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
17
JavaUDSClient/pom.xml
Normal file
17
JavaUDSClient/pom.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>se.rutdev.proxmig</groupId>
|
||||||
|
<artifactId>JavaUDSClient</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>23</maven.compiler.source>
|
||||||
|
<maven.compiler.target>23</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
40
JavaUDSClient/src/main/java/nu/zoom/checked/client/Main.java
Normal file
40
JavaUDSClient/src/main/java/nu/zoom/checked/client/Main.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package nu.zoom.checked.client;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.StandardProtocolFamily;
|
||||||
|
import java.net.UnixDomainSocketAddress;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
new Main().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void run() throws IOException {
|
||||||
|
try (var clientChannel = SocketChannel.open(StandardProtocolFamily.UNIX)) {
|
||||||
|
var serverPath = Path.of("/tmp").resolve("udsserver.sock") ;
|
||||||
|
var serverAddress = UnixDomainSocketAddress.of(serverPath);
|
||||||
|
clientChannel.connect(serverAddress);
|
||||||
|
|
||||||
|
var clientMessage = "quit från - " + UUID.randomUUID();
|
||||||
|
|
||||||
|
sendMessage(clientMessage, clientChannel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendMessage(String clientMessage, SocketChannel clientChannel) throws IOException {
|
||||||
|
var messageBytes = clientMessage.getBytes(StandardCharsets.UTF_8);
|
||||||
|
var messageBuffer = ByteBuffer.allocate(500);
|
||||||
|
messageBuffer.put((byte) messageBytes.length);
|
||||||
|
messageBuffer.put(messageBytes);
|
||||||
|
messageBuffer.flip();
|
||||||
|
clientChannel.write(messageBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MessageToLongException extends Exception {}
|
||||||
|
}
|
17
JavaUDSServer/pom.xml
Normal file
17
JavaUDSServer/pom.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>se.rutdev.proxmig</groupId>
|
||||||
|
<artifactId>JavaUDSServer</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>23</maven.compiler.source>
|
||||||
|
<maven.compiler.target>23</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
49
JavaUDSServer/src/main/java/nu/zoom/checked/server/Main.java
Normal file
49
JavaUDSServer/src/main/java/nu/zoom/checked/server/Main.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package nu.zoom.checked.server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.StandardProtocolFamily;
|
||||||
|
import java.net.UnixDomainSocketAddress;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.ServerSocketChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
new Main().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void run() throws IOException {
|
||||||
|
var path = Path.of("/tmp").resolve("udsserver.sock") ;
|
||||||
|
Files.deleteIfExists(path);
|
||||||
|
var socketAddress = UnixDomainSocketAddress.of(path);
|
||||||
|
ServerSocketChannel serverChannel = ServerSocketChannel
|
||||||
|
.open(StandardProtocolFamily.UNIX);
|
||||||
|
serverChannel.bind(socketAddress);
|
||||||
|
|
||||||
|
boolean keepRunning = true;
|
||||||
|
while (keepRunning) {
|
||||||
|
try (var clientChannel = serverChannel.accept()) {
|
||||||
|
if (clientChannel != null) {
|
||||||
|
var buffer = ByteBuffer.allocate(500);
|
||||||
|
clientChannel.read(buffer);
|
||||||
|
buffer.flip();
|
||||||
|
var length = Byte.toUnsignedInt(buffer.get());
|
||||||
|
if (length < 400 && length > 0) {
|
||||||
|
var rawMessage = new byte[length];
|
||||||
|
buffer.get(rawMessage);
|
||||||
|
var message = new String(rawMessage, StandardCharsets.UTF_8);
|
||||||
|
System.out.println(message);
|
||||||
|
if (message.startsWith("q")) {
|
||||||
|
keepRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serverChannel.close();
|
||||||
|
Files.deleteIfExists(path);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue