| | |
| | | * @return
|
| | | */
|
| | | public static UdpSocketBoot init(int port, UdpSocketOptions options) {
|
| | | return init(null, port, options);
|
| | | return init("0.0.0.0", port, options);
|
| | | }
|
| | |
|
| | |
|
| | |
| | | }
|
| | | if (TextUtils.isEmpty(ipAddress)) {
|
| | | mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(port));
|
| | | }else {
|
| | | mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(ipAddress,port));
|
| | | }
|
| | | mSocket.setBroadcast(true);
|
| | | mSocket.setReuseAddress(true);
|
| | | // mSocket.setReuseAddress(true);
|
| | |
|
| | | } catch (Exception e) {
|
| | | LogUtils.e("初始化Socket 失败:" + e.getMessage());
|
| | |
| | | if (handleMessage != null) {
|
| | | byte[] data = new byte[receivePacket.getLength()];
|
| | | System.arraycopy(receivePacket.getData(), 0, data, 0, data.length);
|
| | | handleMessage.read(data);
|
| | | handleMessage.read(data,receivePacket.getAddress().getHostAddress());
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|