tags:

views:

1043

answers:

10

Hi, i've a java application that create a socketserver in a port. I test my application in a windows machine, and run correctly, but when i test it in a linux machine, the port is not listening.

Is there any way to open port specifically in a linux machine?

I run 'netstat' command, and the port i use in my application doesn't appear. it doesn't throw any exception. i'm trying to connect since another machine to the application, and the connection is refused.

Sincerely, i don't know why it doesn't run...

help please.

thanks, david

A: 

It should work the same. Does it throw an exception on linux? Maybe the target port is occupied already.

Edit: Maybe your code successfully binds to the port but the Linux firewall blocks the incoming connections?

Edit 2: Maybe your Linux JBoss configuration differs and your code which contains the initialization for the ServerSocket is not automatically executed.

kd304
the problem isn't in my code, because it works in a windows machine.the firewall isn't the problem, because it doesn't have it.
+3  A: 

What is the port number you're trying to open ?

If it's below 1024, then only the root user can open it or grant access to it.

Johan Buret
the port number is 1234.i'm the root user
+1  A: 

There should be no difference on Windows and Linux. Can you post an exception-stacktrace, that you most likely get?

The possibilities that are likely are, that your chosen port is already occupied (on Linux usually some services are running) or that you try to bind a port below 1024, that is only allowed for root.

Mnementh
it doesn't throw any exception
A: 

use netstat -napt to check (I don't know which arguments you used).

Aif
i use "netstat -na" and "netstat -na | grep 1234"
any iptables rules?
Aif
A: 

Like Johan Buret said if you are trying to open a port below 1024 you will have to run your program as root or sudo.

if you are running a distro like ubuntu where you are not root and root is not enabled do the following: sudo java SocketServer

if you are a regular user and can su to root fedora/redhat based distros run this: su - (prompt for root's password) java SocketServer

hacintosh
i tried it, but it throws a "ClassNotFoundException: SocketServer"
Are you using Sun Java or gcj? gcj is a open source implementation of java that I have always had trouble with. Try installing the Sun java jdk and jre.
hacintosh
You mean java.net.ServerSocket right?
kd304
A: 

Have you tried connecting from the same machine, to rule out firewall issues?

You can also use telnet to check if the port's open or not

telnet localhost 1234

(will give connection refused if the port isn't open)

Nick
+2  A: 

Are you sure your code is actually being executed? Your comment about the code being in a .sar file implies that you aren't executing it directly, but are deploying it to jboss. Maybe it is not deployed correctly? Have you tried putting some logging statements (or even System.out.println statements) before and after the ServerSocket is created?

Jason Day
+1  A: 

Not really an answer but I don't have enough reputation to comment where I want...

In my experience the cause of most problems for software that works on windows and not Linux is either case sensitivity or access rights somewhere in what you are trying to do. If you're running as root, without any further information I would GUESS that you're swallowing an exception and the bind is failing because the port is taken. Or maybe even you've bound to the wrong server address.

Either way, help those who are trying to help you. Try telnet in as Nick stated. Help Hacintosh by solving the ClassNotFoundError. Don't just sit there saying no, no no my code is perfect guess again! Oh and post some code!

Brad
A: 

I suspect that the JBoss SAR is not configured correctly to start your server. Try the following:

  • Run the JAR file from the Linux command line (as you have successfully on Windows)
  • Install the SAR file into a Windows JBoss installation and see if you get the same issue as on Linux
Matthew Murdoch
A: 

Is SELinux enabled? Try disabling it: http://www.crypt.gen.nz/selinux/disable_selinux.html

Andrew Duffy