Here you can find the source of compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2)
public static int compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2)
//package com.java2s; import java.net.InetSocketAddress; public class Main { public static int compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2) { byte[] addr1Array = addr1.getAddress().getAddress(); byte[] addr2Array = addr2.getAddress().getAddress(); for (int i = 0; i < addr1Array.length && i < addr2Array.length; i++) if (addr1Array[i] < addr2Array[i]) return -1; int port1 = addr1.getPort(); int port2 = addr2.getPort(); if (port1 < port2) return -1; else if (port1 > port2) return 1; else/*w ww. j a v a2 s. c om*/ return 0; } }