Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36201

Re: socket permission problem ?

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject Re: socket permission problem ?
Date 2017-01-18 12:04 -0600
Organization A noiseless patient Spider
Message-ID <o5oakq$m8b$1@dont-email.me> (permalink)
References <alpine.LSU.2.00.1701181716040.8676@cbfrvqba.ynzoengr.vans.vg>

Show all headers | View raw


On 1/18/2017 10:30, Lucio Chiappetti wrote:
> The following test program fails on line     sk.connect(addr);
> on a fresh user of newly installed openSUSE Leap 42.2 machine. The java
> version bundled is
>
> openjdk version "1.8.0_111"
> OpenJDK Runtime Environment (IcedTea 3.2.0) (suse-3.1-x86_64)
> OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
>
> The same program (which is just a tester for a more complex program
> which I am using and would like some students to use on the new machine)
> RUNS HAPPILY since ages on my older machine which is an openSUSE 11.3
> (where however I replaced the OpenJDK with the java-1_6_0-sun packages
>
> java version "1.6.0_10"
> Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
> Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
>
> Neither me, nor the new test user have a .java.policy file in their home
> (anyhow I am quite not familiar with policy files). Neither machine has
> a firewall active.
>
>
> import java.io.BufferedReader;
> import java.io.BufferedWriter;
> import java.io.InputStreamReader;
> import java.io.OutputStreamWriter;
> import java.io.PrintWriter;
> //import java.net.InetAddress;
> import java.net.Socket;
> import java.net.SocketAddress;
>
> public class prova {
>   public static void main(String[] arges) throws Exception {
>
>     Socket sk = new Socket();
>     System.out.println(" DEBUG socket created");
>     sk.bind(null);
>     System.out.println(" DEBUG socket bound to null");
>     SocketAddress addr = sk.getLocalSocketAddress() ;
>     System.out.println(" DEBUG got local address "+addr);
>     sk.connect(addr);
>     System.out.println(" DEBUG socket connected");
>     BufferedReader in = new BufferedReader(new
> InputStreamReader(sk.getInputStream()));
>     System.out.println(" DEBUG  input stream OK");
>     PrintWriter out = new PrintWriter(new BufferedWriter(new
> OutputStreamWriter(sk.getOutputStream())), true);
>     System.out.println(" DEBUG output stream OK");
>     System.out.println("                       ");
>     out.println("ABCD");
>     System.out.println(" written to output channel message ABCD");
>     out.println("XYZT");
>     System.out.println(" written to output channel message XYZT then I
> will read one from input");
>     System.out.println("  read "+in.readLine());
>     out.println("ababab");
>     System.out.println(" written to output channel message ababab");
>     out.println("zxzxzx");
>     System.out.println(" written to output channel message zxzxzx");
>     out.println("maimai");
>     System.out.println(" written to output channel message maimai");
>     System.out.println("  then I will read THREE from input and exit");
>     System.out.println("  read "+in.readLine());
>     System.out.println("  read "+in.readLine());
>     System.out.println("  read "+in.readLine());
>   }
> }
>
> when run on the offending machine it gives
>
>  DEBUG socket created
>  DEBUG socket bound to null
>  DEBUG got local address 0.0.0.0/0.0.0.0:48070
> Exception in thread "main" java.net.ConnectException: Connection refused
> (Connection refused)
>         at java.net.PlainSocketImpl.socketConnect(Native Method)
>         ...
>         at java.net.Socket.connect(Socket.java:538)
>         at prova.main(prova.java:19)
>
> Any easy way out ?
> Thanks

I think this is a linux problem caused by the kernel security features 
that prevent local connections.  It runs fine on Windows but on my 
Xubuntu it fails as above.  I've seen this before and I thought you 
could fix it by modifying some of the options in 
/etc/sysctl.d/99-sysctl.conf but I couldn't get it to work.  I'm sure 
that's where you will find the solution however.

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

socket permission problem ? Lucio Chiappetti <nospam@iasf-milano.inaf.it> - 2017-01-18 17:30 +0100
  Re: socket permission problem ? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-01-18 12:04 -0600
    Re: socket permission problem ? Lucio Chiappetti <nospam@iasf-milano.inaf.it> - 2017-01-25 16:48 +0100

csiph-web