89 * The launched process will inherit a connected TCP socket. The remote endpoint |
90 * The launched process will inherit a connected TCP socket. The remote endpoint |
90 * will be the SocketChannel returned by this method. |
91 * will be the SocketChannel returned by this method. |
91 */ |
92 */ |
92 public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException { |
93 public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException { |
93 ServerSocketChannel ssc = ServerSocketChannel.open(); |
94 ServerSocketChannel ssc = ServerSocketChannel.open(); |
94 ssc.socket().bind(new InetSocketAddress(0)); |
95 ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0)); |
95 InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), |
96 InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), |
96 ssc.socket().getLocalPort()); |
97 ssc.socket().getLocalPort()); |
97 SocketChannel sc1 = SocketChannel.open(isa); |
98 SocketChannel sc1 = SocketChannel.open(isa); |
98 SocketChannel sc2 = ssc.accept(); |
99 SocketChannel sc2 = ssc.accept(); |
99 launch(className, options, args, Util.getFD(sc2)); |
100 launch(className, options, args, Util.getFD(sc2)); |
118 */ |
119 */ |
119 public static SocketChannel launchWithServerSocketChannel(String className, String options[], String args[]) |
120 public static SocketChannel launchWithServerSocketChannel(String className, String options[], String args[]) |
120 throws IOException |
121 throws IOException |
121 { |
122 { |
122 ServerSocketChannel ssc = ServerSocketChannel.open(); |
123 ServerSocketChannel ssc = ServerSocketChannel.open(); |
123 ssc.socket().bind(new InetSocketAddress(0)); |
124 ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0)); |
124 int port = ssc.socket().getLocalPort(); |
125 int port = ssc.socket().getLocalPort(); |
125 launch(className, options, args, Util.getFD(ssc)); |
126 launch(className, options, args, Util.getFD(ssc)); |
126 ssc.close(); |
127 ssc.close(); |
127 InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), port); |
128 InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), port); |
128 return SocketChannel.open(isa); |
129 return SocketChannel.open(isa); |
145 * sent to the service. |
146 * sent to the service. |
146 */ |
147 */ |
147 public static DatagramChannel launchWithDatagramChannel(String className, String options[], String args[]) |
148 public static DatagramChannel launchWithDatagramChannel(String className, String options[], String args[]) |
148 throws IOException |
149 throws IOException |
149 { |
150 { |
|
151 InetAddress address = InetAddress.getLocalHost(); |
|
152 if (address.isLoopbackAddress()) { |
|
153 address = InetAddress.getLoopbackAddress(); |
|
154 } |
150 DatagramChannel dc = DatagramChannel.open(); |
155 DatagramChannel dc = DatagramChannel.open(); |
151 dc.socket().bind(new InetSocketAddress(0)); |
156 dc.socket().bind(new InetSocketAddress(address, 0)); |
152 |
157 |
153 int port = dc.socket().getLocalPort(); |
158 int port = dc.socket().getLocalPort(); |
154 launch(className, options, args, Util.getFD(dc)); |
159 launch(className, options, args, Util.getFD(dc)); |
155 dc.close(); |
160 dc.close(); |
156 |
161 |
157 dc = DatagramChannel.open(); |
162 dc = DatagramChannel.open(); |
158 InetAddress address = InetAddress.getLocalHost(); |
|
159 if (address.isLoopbackAddress()) { |
|
160 address = InetAddress.getLoopbackAddress(); |
|
161 } |
|
162 InetSocketAddress isa = new InetSocketAddress(address, port); |
163 InetSocketAddress isa = new InetSocketAddress(address, port); |
163 |
164 |
164 dc.connect(isa); |
165 dc.connect(isa); |
165 return dc; |
166 return dc; |
166 } |
167 } |