Code example for DatagramSocket

Methods: close, isClosed, isConnected

0
		public packetSender(DatagramPacket pack){
			this.packet=pack;
		} 
		public void run() { 
			try{ 
				if((socket==null)||(!socket.isConnected())||(socket.isClosed())){
					if((!(socket==null))&&(!(socket.isClosed())))
					{Log.d("closing", "socket");
					socket.close();}
					socket=null;
					socket=new DatagramSocket();//port binding not required as not listening here
				} 
				socket.send(packet);
				socket.close();
			} 
			 
			catch(SocketException e){
				Log.d("error","Socket conn error");
				e.printStackTrace();
			} catch (IOException e) {
				Log.d("error","Socket sending error");