Results 1 to 3 of 3
Thread: Socket programming - port issues
- 11-06-2007, 07:42 PM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
Socket programming - port issues
Review the code below:
I have hard coded the port. If port is already occupied, exception will be thrown. I want to catch that exception and want my program to retry by adding 1 to it until connection is made. How this can be done?Java Code:int PortNumber = 1500; ServerSocket MyService; try { MyServerice = new ServerSocket(PortNumber); } catch (IOException e) { System.out.println(e); }
- 11-06-2007, 07:53 PM #2
Place your connection code inside a method, define port as a variable of the class, and when you catch appropriate exception, increase port number and recall yourself.
- 11-07-2007, 10:24 AM #3
Senior Member
- Join Date
- Nov 2007
- Posts
- 115
- Rep Power
- 0
Similar Threads
-
Serial Port
By radhika in forum New To JavaReplies: 5Last Post: 11-06-2009, 10:40 AM -
Socket programming - accepting files
By ravian in forum NetworkingReplies: 2Last Post: 11-29-2007, 10:40 AM -
Programming Socket Question
By paul in forum NetworkingReplies: 1Last Post: 07-30-2007, 07:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks