Code example for DatagramSocket

Methods: getLocalPort

0
	} 
 
	public int init() { 
		try { 
			srvSocket = new DatagramSocket(0,
					InetAddress.getByName("127.0.0.1"));
			inService = true;
			srvPort = srvSocket.getLocalPort();
			Log.e(TAG, this.name + "启动于端口: " + srvPort);
		} catch (SocketException e) {
			Log.e(TAG, "DNSServer初始化错误,端口号" + srvPort, e);
		} catch (UnknownHostException e) {
			Log.e(TAG, "DNSServer初始化错误,端口号" + srvPort, e);
		} 
		return srvPort;
	} 
 
	@Override 
	public boolean isClosed() { 
		return srvSocket.isClosed();
	}