daily_automated

This commit is contained in:
topicchi
2023-03-17 11:59:21 +00:00
parent 252ecca9cf
commit e2f276193e
4496 changed files with 1178007 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class UDPClient {
public static void main(String[] args) throws UnknownHostException {
DatagramSocket s;
byte[] sendBuffer = new byte[1024];
DatagramPacket sendPacket;
final InetAddress ADDRESS = InetAddress.getByName("localhost");
final int PORT = 1234;
try {
s = new DatagramSocket();
System.out.println("Odesilam data na server...");
sendBuffer = "abc123".getBytes();
sendPacket = new DatagramPacket(sendBuffer, sendBuffer.length,
ADDRESS, PORT);
s.send(sendPacket);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,39 @@
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.text.SimpleDateFormat;
import java.util.Date;
public class UDPserver {
public static void main(String[] args) {
UDPserver server = new UDPserver(1234);
server.start();
}
private int port;
private DatagramSocket s;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public UDPserver(int port) {
this.port = port;
}
public void start() {
System.out.println("SERVER: Waiting for incomming connections...");
System.out.println("DATE TIME IP:PORT received_data");
try {
s = new DatagramSocket(this.port);
while (true) {
byte[] data = new byte[1412];
DatagramPacket p = new DatagramPacket(data,
data.length);
s.receive(p);
System.out.print(sdf.format(new Date()).toString() + " ");
System.out.print(p.getSocketAddress() + " ");
System.out.println(new String(p.getData()));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}