MCPcopy Create free account
hub / github.com/demoth/jake2 / Socket

Method Socket

qcommon/src/main/java/jake2/qcommon/network/NET.java:223–254  ·  view source on GitHub ↗
(int sock, String ip, int port)

Source from the content-addressed store, hash-verified

221 * Socket
222 */
223 public static DatagramSocket Socket(int sock, String ip, int port) {
224 DatagramSocket newsocket = null;
225 try {
226 if (ip_channels[sock] == null || !ip_channels[sock].isOpen())
227 ip_channels[sock] = DatagramChannel.open();
228
229 if (ip == null || ip.length() == 0 || ip.equals("localhost")) {
230 if (port == Defines.PORT_ANY) {
231 newsocket = ip_channels[sock].socket();
232 newsocket.bind(new InetSocketAddress(0));
233 } else {
234 newsocket = ip_channels[sock].socket();
235 newsocket.bind(new InetSocketAddress(port));
236 }
237 } else {
238 InetAddress ia = InetAddress.getByName(ip);
239 newsocket = ip_channels[sock].socket();
240 newsocket.bind(new InetSocketAddress(ia, port));
241 }
242
243 // nonblocking channel
244 ip_channels[sock].configureBlocking(false);
245 // the socket have to be broadcastable
246 newsocket.setBroadcast(true);
247 Com.Println("Opened port: " + port);
248 } catch (Exception e) {
249 Com.Println("jake2.qcommon.network.NET.Socket: " + e.toString());
250 e.printStackTrace();
251 newsocket = null;
252 }
253 return newsocket;
254 }
255
256 /**
257 * Shutdown - closes the sockets

Callers 1

OpenIPMethod · 0.95

Calls 3

PrintlnMethod · 0.95
equalsMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected