java - Socket program for Server using System IP Address -


i'm trying run server application in pc using serversocket, trying system's ip address start server , wait client connect, i've written,

inetaddress inetaddress = inetaddress.getlocalhost(); serversocket serversocket; if (serversocket == null) serversocket = new serversocket(1000, 0, inetaddress); socket socket=serversocket.accept(); 

its working correctly in window os, when try application in unix os not working me, tried print ip address using,

system.out.println(inetaddress.gethostaddress); 

in windows os correct ip address gets printed in unix os, got was

127.0.0.1

so server not working, have not tried in mac os, there way start server using system's default ip address in os.

thanks.

this appears pretty common issue. see following links possible solutions: java inetaddress.getlocalhost(); returns 127.0.0.1 ... how real ip?

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037

specifically, work around , evaluation in sun bug link explains how function works on linux , how make sure linux box set return correct ip when queried java.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -