Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket Issue on Unix, but the same java code works on Windows  RSS feed

 
Michel Dambros Figueiredo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi

I have the java program bellow that works when performed on windows 8, but when I publish the program on a unix server, it does not work and throws a timenout on din.read() method.

Please, does anybody know how to solve it ?


socket2 = new Socket (ip, porta);
socket2.setSoTimeout(3000);
PrintStream pout = new PrintStream ( socket2.getOutputStream() );
DataInputStream din = new DataInputStream( socket2.getInputStream() );
pout.println("GST"); //I am not sure if the other side is receiving this command
pout.flush();
int retint = din.read(); //here is the timeout
System.out.println( retint );
fechaSocket(socket2);
return ""+ retint;
 
Henry Wong
author
Sheriff
Posts: 22833
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michel Dambros Figueiredo wrote:I have the java program bellow that works when performed on windows 8, but when I publish the program on a unix server, it does not work and throws a timenout on din.read() method.

Please, does anybody know how to solve it ?


There is nothing in this code that should show a difference based on Windows or Unix. Whatever the issue, it is likely related to the network or operation system configurations. I would recommend check the network, to see if how they are configured, or check the OSes for something like a firewall, etc.

Henry
 
Michel Dambros Figueiredo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry, thank you for the answer.

I already made a check connection in the operation system using telnet, and it worked. So the issue can not be related to the network or operation system.

May it be related to the JVM or the application server ? remembering that the socket command works, and the fail occurs just when I try the read the return sent from the other site

 
Henry Wong
author
Sheriff
Posts: 22833
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michel Dambros Figueiredo wrote:
May it be related to the JVM or the application server ? remembering that the socket command works, and the fail occurs just when I try the read the return sent from the other site


Can you be a bit more clear? When you say that it works with windows but not with unix, are you saying that in windows, it gets the response, but not in unix? When you say it works when you telnet, are you saying it works in both windows and unix, and you get the response in both cases?

Henry
 
Ron McLeod
Saloon Keeper
Posts: 1425
206
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the best approach would be to grab a network trace using snoop/tcpdump/wireshark and see if you are establishing a connection to the other side, if your data is being send, if anything is being returned, etc.

What is your unix platform - Linux, Solaris, BSD, ??
 
Michel Dambros Figueiredo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,

yes, it gets the response in Windows but not in unix.

it Works when I telnet in both Windows and unix, and I get the response in both cases.


Henry Wong wrote:
Michel Dambros Figueiredo wrote:
May it be related to the JVM or the application server ? remembering that the socket command works, and the fail occurs just when I try the read the return sent from the other site


Can you be a bit more clear? When you say that it works with windows but not with unix, are you saying that in windows, it gets the response, but not in unix? When you say it works when you telnet, are you saying it works in both windows and unix, and you get the response in both cases?

Henry
 
Michel Dambros Figueiredo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron McLeod, thank you for your answer.

My platform is Red Hat 6.

The telnet command Works when I connect from the unix shell, and I got the answer.




Ron McLeod wrote:I think the best approach would be to grab a network trace using snoop/tcpdump/wireshark and see if you are establishing a connection to the other side, if your data is being send, if anything is being returned, etc.

What is your unix platform - Linux, Solaris, BSD, ??
 
Henry Wong
author
Sheriff
Posts: 22833
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michel Dambros Figueiredo wrote:
The telnet command Works when I connect from the unix shell, and I got the answer.


If telnet works with a response for both Windows and Unix. And if the Java application works for Windows, then the only possibility that I can think of is the timeout -- perhaps the Unix environment is just slower than the Windows environment. Try increasing the timeout.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!