-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
executable file
·48 lines (39 loc) · 2.15 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
UdpSocket, MIT (c) 2019,2021 [email protected]
Java SE 7+ UDP broadcast/unicast/multicast sender/receiver
Release notes:
- don't forget to open the required UDP port in your firewall;
- the socket type (datagram/multicast) is determined by the requested address (inetAddr);
- the created socket is bound to the port and specified bind address (bindAddr);
- multicast sockets are created with loopback disabled and one hop;
- the datagram socket connects to a non-broadcast, not anyLocal address;
- only non-multicast IPv4 addresses ending in .255 are considered broadcast;
- DO NOT disable datagram socket timeout.
package org.miktim.udpsocket;
Overview:
Class UdpSocket extends Thread;
Constructors:
UdpSocket(int port) throws IOException; // broadcast datagram socket (255.255.255.255)
UdpSocket(int port, InetAddress inetAddr) throws IOException;
UdpSocket(int port, InetAddress inetAddr, InetAddress bindAddr) throws IOException;
Methods:
static void setReuseAddress(boolean on); // enabled by default
static boolean getReuseAddress();
static void send(byte[] buf, InetAddress addr, int port) throws IOException; // send datagram
void send(byte[] buf) throws IOException; // send using socket
void send(byte[] buf, InetAddress addr) throws IOException; // send using socket
void send(byte[] buf, int port, InetAddress addr) throws IOException; // send using socket
void setBufLength(int len); // set the buffer length of the receiving datagram packets
int getBufLength();
void receive(UdpSocket.Handler handler); // start receiving datagrams
void close(); // stop receiving, close datagram socket
boolean isOpen();
boolean isReceiving();
boolean isMulticast();
boolean isBroadcast();
InetAddress getInetAddress(); // returns inetAddr parameter
DatagramSocket getDatagramSocket();
Interface UdpSocket.Handler:
void onStart(UdpSocket socket);
void onPacket(UdpSocket socket, DatagramPacket packet);
void onError(UdpSocket socket, Exception e);
void onClose(UdpSocket socket); // called BEFORE closing the datagram socket