Code example for DatagramSocket

Methods: connect, setSoTimeout

0
 
	private ChatManager() { 
		try { 
			// Setup the connection 
			InetAddress adrServer = InetAddress.getByName(SERVER);
			sockCmd = new DatagramSocket(4000);
			sockCmd.setSoTimeout(10 * 1000); // read timeout of 10s
			sockCmd.connect(adrServer, 4000); // set default socket for send/recv
 
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (SocketException e) {
			e.printStackTrace();
		} 
	} 
	 
	public MessageHandler getHandler() { 
		return this.handler;
	} 
 
	/**