Try using junixsocket 2.6.1 to connect, but get error
Cannot connect to server. Have you started it?
Exception in thread "main" java.net.SocketException:
at org.newsclub.net.unix.NativeUnixSocket.connect(Native Method)
at org.newsclub.net.unix.AFSocketImpl.connect0(AFSocketImpl.java:392)
at org.newsclub.net.unix.AFSocket.connect0(AFSocket.java:267)
at org.newsclub.net.unix.AFSocket.connect(AFSocket.java:236)
at org.newsclub.net.unix.AFSocket.connect(AFSocket.java:231)
at org.newsclub.net.unix.AFSocket.connectTo(AFSocket.java:179)
at org.newsclub.net.unix.AFUNIXSocket.connectTo(AFUNIXSocket.java:109)
at junixsocket.SimpleTestClient.main(SimpleTestClient.java:31)
**To Reproduce**
Steps to reproduce the behavior:
This is Python3.9 Domain Server Code
if name == "main":
socket_server_obj = SocketServer()
socket_server_obj.wait_and_deal_client_connect()
And this is junixsock client
```java
public class SimpleTestClient {
public static void main(String[] args) throws IOException {
final File socketFile = new File(new File(System.getProperty("java.io.tmpdir")),
"junixsocket-test.sock");
boolean connected = false;
try (AFUNIXSocket sock = AFUNIXSocket.connectTo(AFUNIXSocketAddress.of(socketFile));
InputStream is = sock.getInputStream(); //
OutputStream os = sock.getOutputStream();
DataInputStream din = new DataInputStream(is);
DataOutputStream dout = new DataOutputStream(os);) {
System.out.println("Connected");
connected = true;
byte[] buf = new byte[128];
int read = is.read(buf);
System.out.println("Server says: " + new String(buf, 0, read, "UTF-8"));
System.out.println("Replying to server...");
os.write("Hello Server".getBytes("UTF-8"));
os.flush();
System.out.println("Now reading numbers from the server...");
while (!Thread.interrupted()) {
int number = din.readInt();
if (number == -123) {
// by convention of this demo, if the number is -123, we stop.
// If we don't do this, we'll get an EOFException upon the next unsuccessful read.
break;
}
System.out.println(number);
int ourNumber = number * 2;
System.out.println("Sending back " + ourNumber);
dout.writeInt(ourNumber);
}
} catch (SocketException e) {
if (!connected) {
System.out.println("Cannot connect to server. Have you started it?");
System.out.println();
}
throw e;
}
System.out.println("End of communication.");
}
}
Expected behavior
Output/Screenshots
If applicable, add console output/screenshots to help explain your problem.
Environment (please complete the following information):
OS: Ubuntu20.02 ON Win10 WSL2
Please also add the output of java -jar junixsocket-selftest-x.y.z-SNAPSHOT-jar-with-dependencies.jar (x.y.z being the latest version, e.g., 2.3.3). — The selftest jar is available from the junixsocket-dist package in the Release section.
Notes
Add any other context about the problem here. Please link/attach any source code that is useful to diagnose the issue.
Lastly, please make sure to test the problem still occurs on the latest version of junixsocket
All minor version updates (e.g., 2.4.x -> 2.5.x) are supposed to be backwards compatible.
If you find that this isn't the case, please mention it in your report. Thank you!
Describe the bug
Exception in thread "main" java.net.SocketException: at org.newsclub.net.unix.NativeUnixSocket.connect(Native Method) at org.newsclub.net.unix.AFSocketImpl.connect0(AFSocketImpl.java:392) at org.newsclub.net.unix.AFSocket.connect0(AFSocket.java:267) at org.newsclub.net.unix.AFSocket.connect(AFSocket.java:236) at org.newsclub.net.unix.AFSocket.connect(AFSocket.java:231) at org.newsclub.net.unix.AFSocket.connectTo(AFSocket.java:179) at org.newsclub.net.unix.AFUNIXSocket.connectTo(AFUNIXSocket.java:109) at junixsocket.SimpleTestClient.main(SimpleTestClient.java:31)
import socket
class SocketServer: def init(self):
常规tcp监听写法
if name == "main": socket_server_obj = SocketServer() socket_server_obj.wait_and_deal_client_connect()
Expected behavior
Output/Screenshots If applicable, add console output/screenshots to help explain your problem.
Environment (please complete the following information):
Please also add the output of
java -jar junixsocket-selftest-x.y.z-SNAPSHOT-jar-with-dependencies.jar
(x.y.z being the latest version, e.g., 2.3.3). — The selftest jar is available from the junixsocket-dist package in the Release section.Notes Add any other context about the problem here. Please link/attach any source code that is useful to diagnose the issue.
Lastly, please make sure to test the problem still occurs on the latest version of junixsocket All minor version updates (e.g., 2.4.x -> 2.5.x) are supposed to be backwards compatible. If you find that this isn't the case, please mention it in your report. Thank you!