Code example for DatagramSocket

Methods: connect

0
		private byte[] data = new byte[50];
	    private String ipAddress = "192.168.1.12";
 
	public ConnectionManager() { 
		try { 
			socket = new DatagramSocket(8889);
			socket.connect(InetAddress.getByName(ipAddress), 9999);
 
		} catch (SocketException e) {
			Log.e(TAG, e.getMessage());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} 
	} 
	 
	public void send(){ 
		DatagramPacket pk = new DatagramPacket(data, data.length);
		Log.d(TAG, "Packet sending");
		try { 
			socket.send(pk);
			Log.d(TAG, "Packet sent");