Code example for DatagramSocket

Methods: bind, getLocalAddress, setReuseAddress

0
		public VoiceServer(){ 
			 
			try{ 
				 
				//serverAddr = InetAddress.getByName(ipAddress); 
				socket = new DatagramSocket(null);
				socket.setReuseAddress(true);
				socket.bind(new InetSocketAddress(portNumber));
				 
				Log.d("SERVER", "Listening at: " + socket.getLocalAddress());
				//socket.connect(InetAddress.getByName(ipAddress), portNumber); 
				//Log.d("SERVER", "Listening at: " + socket.getInetAddress().getHostAddress()); 
			} 
			catch(SocketException e){
				e.printStackTrace();
				Log.d("VoiceServer", "Exception has occured trying open a socket.");
				Log.d("VoiceServer", "Details:" + e.getMessage());
			} 
		} 
		 
		@Override