java.net.ConnectException: Invalid argument ???

P

Peter D.

java.net.ConnectException: Invalid argument
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:
333)
at java.net.PlainSocketImpl.connectToAddress
(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
...

I have a simple program that can send and receive UDP data via sockets
with Java. In windows this app works perfectly but on Ubuntu 8.04 I
get this error. I don't seem to be the only one with this issue as
there are a couple of pages on this from google. No one seems to have
any idea as to why this is happening but from my research there seems
to be a pattern. This seems to be affecting people using the JDK6 and
some sort of UNIX operating system but not everyone. I have tried
suggestions like forcing ipv4 on the jvm and testing small main
classes to see if it's something with my code but this seems to happen
on all socket connections.

In my case I am using:

java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

On Ubuntu 8.04.

I would be grateful for any ideas or suggestions.
 
G

grasp06110

java.net.ConnectException: Invalid argument
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:
333)
        at java.net.PlainSocketImpl.connectToAddress
(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        ...

I have a simple program that can send and receive UDP data via sockets
with Java. In windows this app works perfectly but on Ubuntu 8.04 I
get this error. I don't seem to be the only one with this issue as
there are a couple of pages on this from google. No one seems to have
any idea as to why this is happening but from my research there seems
to be a pattern. This seems to be affecting people using the JDK6 and
some sort of UNIX operating system but not everyone. I have tried
suggestions like forcing ipv4 on the jvm and testing small main
classes to see if it's something with my code but this seems to happen
on all socket connections.

In my case I am using:

java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

On Ubuntu 8.04.

I would be grateful for any ideas or suggestions.

Could it be a permissions issue? I have often seen problems porting
things to unix/linux that trace back to a process not having adequate
permissions on a resource. Sad to say I've wasted so much time on
this I have a little sticky note above my desk that has the single
word "permissions" on it to remind me of this :cool:

Hope this helps,
John
 
P

Peter D.

Could it be a permissions issue?  I have often seen problems porting
things to unix/linux that trace back to a process not having adequate
permissions on a resource.  Sad to say I've wasted so much time on
this I have a little sticky note above my desk that has the single
word "permissions" on it to remind me of this :cool:

Hope this helps,
John

Hi thanks for the reply, if by permissions you mean running the app
with the proper privileges I have tried running it as root with no
success. :(
 
P

Peter D.

java.net.ConnectException: Invalid argument
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:
333)
        at java.net.PlainSocketImpl.connectToAddress
(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        ...

I have a simple program that can send and receive UDP data via sockets
with Java. In windows this app works perfectly but on Ubuntu 8.04 I
get this error. I don't seem to be the only one with this issue as
there are a couple of pages on this from google. No one seems to have
any idea as to why this is happening but from my research there seems
to be a pattern. This seems to be affecting people using the JDK6 and
some sort of UNIX operating system but not everyone. I have tried
suggestions like forcing ipv4 on the jvm and testing small main
classes to see if it's something with my code but this seems to happen
on all socket connections.

In my case I am using:

java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

On Ubuntu 8.04.

I would be grateful for any ideas or suggestions.

Well, I think I found the problem and I'll post it here if anyone
happens to run across this issue as well. In Linux it is possible to
have many IP address and many network interfaces. For some reason the
JVM on Linux just decides to pull the first interface it can find. If
that interface happens to be the loopback interface then thats the IP
address you are going to get.

I THINK that binding to a port on the loopback was my problem. By
checking every interface and choosing the proper one to bind to my
problem was resolved. I no longer get the error posted above.

To get a list of all the network interfaces:

Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces
();
 
L

Lew

Peter said:
In Linux it is possible to
have many IP address and many network interfaces. For some reason the

Other OSes, such as Windows, have this feature as well.
 
A

Arne Vajhøj

Lew said:
Other OSes, such as Windows, have this feature as well.

I would assume that most OS'es have it. Unix has it. OpenVMS
has it. I am pretty sure that z/OS has it.

Arne
 
E

EJP

The problem appears to be that you are using a java.net.Socket for UDP.
Use a DatagramSocket.
For some reason the JVM on Linux just decides to pull the first interface it can find.

No it doesn't. It uses the interface you specify, or IPADDR_ANY.
 
P

Peter D.

The problem appears to be that you are using a java.net.Socket for UDP.
Use a DatagramSocket.


No it doesn't. It uses the interface you specify, or IPADDR_ANY.

Yes but. On Windows:

wSocket = new DatagramSocket( listenPort );

Binds the connection to 192.168.0.2 or whatever your interface
provides.

On Linux in binds to: 127.0.0.1

I windows the loopback interface does not actually seem to be
presented as an adapter. In Linux it is "lo".

ipconfig in Windows returns only 1 interface. Typing ifconfig on linux
returns the "lo" interface first then "eth0".

I assumed that in Linux, if you don't specify an adapter to bind to it
will choose the first one available.
 
E

EJP

Yes but. On Windows:

wSocket = new DatagramSocket( listenPort );

Binds the connection to 192.168.0.2 or whatever your interface
provides.
No, it binds to INADDR_ANY, 0.0.0.0.
On Linux in binds to: 127.0.0.1
No, it binds to INADDR_ANY, 0.0.0.0.
I assumed that in Linux, if you don't specify an adapter to bind to it
will choose the first one available.
No, it binds to INADDR_ANY, 0.0.0.0.

Does your /etc/hosts file by any chance associate your external IP
address with 'localhost', or your external hostname with 127.0.0.1?
This is a well-known Linux distribution problem. It should map
127.0.0.1 to localhost, and your external IP address to your external
hostname.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top