Code example for DatagramSocket

Methods: connect

0
            try { 
                if (type == Type.TCP) {
                    tcpSocket = new Socket(address, port);
                } else { 
                    if (udpSocket == null) {
                        udpSocket = new DatagramSocket();
                    } 
                    this.port = port;
                    this.address = InetAddress.getByName(address);
                    this.connected = true;
                    udpSocket.connect(this.address, port);
                } 
                init(); 
            } catch(UnknownHostException uhe) {
                Log.e(LOG_TAG, "Unknown host exception while connecting socket", uhe);
                return false; 
            } catch(IOException ioe) {
                Log.e(LOG_TAG, "IOException while connecting socket", ioe);
                return false; 
            } 
            return true;