Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:00:52+00:00 2026-06-17T13:00:52+00:00

How to write this socket stream on local file system client in Java? Python

  • 0

How to write this socket stream on local file system client in Java?

Python works:

# Echo server program
import socket,os

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
    os.remove("/tmp/socketname")
except OSError:
    pass
s.bind("/tmp/socketname")
s.listen(1)
conn, addr = s.accept()
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()


# Echo client program
import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/tmp/socketname")
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)

Java:

  /* Client: how do you mention the /tmp/socketname? */
  public static String localsendTCPBytes(String bytes) throws IOException {
    String downloaded = null;
    Socket socket = new Socket("localhost", 58888);
    DataOutputStream upload = new DataOutputStream(socket.getOutputStream());
    BufferedReader download = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    String caps = bytes;
    upload.writeBytes(caps);
    upload.flush();
    String get;
    downloaded = download.readLine();
    System.out.println("[TCP]: downloading: " + downloaded);
    socket.close();
    return downloaded;
  }

Follow up:

1) Import jar and attach to the project:

JUnixsocket – download JAR

2) Unitest Java client code

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.newsclub.net.unix.AFUNIXSocket;
import org.newsclub.net.unix.AFUNIXSocketAddress;
import org.newsclub.net.unix.AFUNIXSocketException;

public class SimpleTestClient {
  public static void main(String[] args) throws IOException {
    final File socketFile = new File("/tmp/socketname");
    AFUNIXSocket sock = AFUNIXSocket.newInstance();
    try {
      sock.connect(new AFUNIXSocketAddress(socketFile));
    } catch (AFUNIXSocketException e) {
      System.out.println("Cannot connect to server. Have you started it?");
      System.out.flush();
      throw e;
    }
    System.out.println("Connected");
    InputStream is = sock.getInputStream();
    OutputStream os = sock.getOutputStream();
    byte[] buf = new byte[128];
    int read = is.read(buf);
    System.out.println("Server says: " + new String(buf, 0, read));
    System.out.println("Replying to server...");
    os.write("Hello Server".getBytes());
    os.flush();
    os.close();
    is.close();
    sock.close();
    System.out.println("End of communication.");
  }
}

3) Build/compile problem:

java.lang.UnsatisfiedLinkError: Could not load junixsocket library, tried [/opt/newsclub/lib-native/libjunixsocket-linux-1.6-amd64.so, /opt/newsclub/lib-native/libjunixsocket-linux-1.5-amd64.so, lib:junixsocket-linux-1.6-amd64, lib:junixsocket-linux-1.5-amd64]; please define system property org.newsclub.net.unix.library.path
    at org.newsclub.net.unix.NativeUnixSocket.load(NativeUnixSocket.java:95)
    at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:105)
    at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
    at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:50)
    at unixdomainsocket.SimpleTestClient.main(SimpleTestClient.java:26)
Caused by: java.lang.UnsatisfiedLinkError: no junixsocket-linux-1.5-amd64 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
    at java.lang.Runtime.loadLibrary0(Runtime.java:840)
    at java.lang.System.loadLibrary(System.java:1047)
    at org.newsclub.net.unix.NativeUnixSocket.load(NativeUnixSocket.java:77)
    ... 4 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.newsclub.net.unix.NativeUnixSocket
    at org.newsclub.net.unix.AFUNIXSocketImpl.connect(AFUNIXSocketImpl.java:125)
    at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:97)
    at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:87)
    at unixdomainsocket.SimpleTestClient.main(SimpleTestClient.java:28)
Java Result: 1

4) Solution:

-Djava.library.path=/usr/lib/jni -Djava.library.path=/usr/lib/rxtx -Djava.security.policy=applet.policy -Djava.library.path=/var/tmp/screwyou/jar/lib-native

Works!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:00:53+00:00Added an answer on June 17, 2026 at 1:00 pm

    You can’t use Unix domain sockets from the Java JDK. You would need an external package, if you can find one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following basic server/client java code, that works when server and client
I trying to write a client server application in Python, but I faced a
my client program first connects to server,then server send a file and then client
I want to create a data packet and write it to socket. This packet
I write this code to get Dunnet anova post hoc test import rpy2.robjects as
i write this code in main.java ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); try{ HttpClient httpclient
I write this function, but what's its return value. (defn read-data [file] (let [code
I am trying to write this loop in Python but get confused. Basically I
I am extremely new to socket programming and I am implementaing a file server
I am trying to write a program that works as an intermedium. (M) I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.