Code example for DatagramSocket

Methods: getLocalPort

0
	} 
 
	public int init() { 
		try { 
			srvSocket = new DatagramSocket(0,
					InetAddress.getByName("127.0.0.1"));
			Log.e("srvSocket", srvSocket.getLocalPort()+"");
			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();