0

I had created a console application in which i was trying to create a socket connection with the server using

Java Class ServerConnect----

InetAddress hostIpAddress= fnGetHostInetAddress(domainName);  
System.out.println(hostIpAddress.getHostAddress()+""+hostIpAddress.getHostName());  
Socket socket = new Socket(hostIpAddress,43);  

The console java application properly created the socket connection but...

When i tried to do the same thing through the Swing application i.e by giving call to the function of ServerConnect class for Socket Connection it did not work. When i tried to debug the Swing Application the control hanged at line

Socket socket = new Socket(hostIpAddress,43);

and did not move further, not even gave any exception.I am using netbeans IDE. The above code snippet is written in a function within a thread class ServerConnect which implements runnable interface whose run method gives call to that function.

call to start the thread is given in the actionPerformed method of a button.

Can anybody suggest what might be the problem/error.

Thanks

Nishit Jain
  • 1,549
  • 8
  • 21
  • 33

1 Answers1

3

How are you getting the domain name in your Swing app? Are you sure you read it correctly?

Other possibility is that if you call this code from the Swing event dispatch thread (EDT), eg. from an action listener, it could upset the EDT and cause some problems. Try running it in a new thread.

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
  • fnGetHostInetAddress is user defined function returns the ipAddress of the domainname(String) yes i have checked it returns correct IP Address – Nishit Jain Mar 01 '12 at 08:57
  • @NishitJain: Compare your code to this working [example](http://stackoverflow.com/a/3245805/230513), which does _not_ block the EDT. +1 – trashgod Mar 01 '12 at 10:17