Filters used:
Know more about the effect of the filter UV-IR CUT and Hoya R72, read "RPi NoIR V2 Camera vs UV-IR CUT vs 720nm Infrared (Hoya R72) filter".
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Date;
/*
reference:
https://docs.oracle.com/javase/tutorial/networking/datagrams/clientServer.html
*/
public class JavaUdpServer {
static UdpServerThread udpServerThread;
public static void main(String[] args) throws IOException {
System.out.println("Server start");
System.out.println("Runtime Java: "
+ System.getProperty("java.runtime.version"));
new UdpServerThread().start();
}
private static class UdpServerThread extends Thread{
final int serverport = 4445;
protected DatagramSocket socket = null;
public UdpServerThread() throws IOException {
this("UdpServerThread");
}
public UdpServerThread(String name) throws IOException {
super(name);
socket = new DatagramSocket(serverport);
System.out.println("JavaUdpServer run on: " + serverport);
}
@Override
public void run() {
while(true){
try {
byte[] buf = new byte[256];
// receive request
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
String dString = new Date().toString();
buf = dString.getBytes();
// send the response to the client at "address" and "port"
InetAddress address = packet.getAddress();
int port = packet.getPort();
System.out.println("Request from: " + address + ":" + port);
packet = new DatagramPacket(buf, buf.length, address, port);
socket.send(packet);
} catch (IOException ex) {
System.out.println(ex.toString());
}
}
}
}
}
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
/*
reference:
https://docs.oracle.com/javase/tutorial/networking/datagrams/clientServer.html
*/
public class JavaUdpClient {
public static void main(String[] args)
throws UnknownHostException, SocketException, IOException {
//Hardcode ip:port
String ipLocalLoopback = "127.0.0.1";
int serverport = 4445;
System.out.println("Runtime Java: "
+ System.getProperty("java.runtime.version"));
System.out.println("JavaUdpClient running, connect to: "
+ ipLocalLoopback + ":" + serverport);
// get a datagram socket
DatagramSocket socket = new DatagramSocket();
// send request
byte[] buf = new byte[256];
InetAddress address = InetAddress.getByName(ipLocalLoopback);
DatagramPacket packet =
new DatagramPacket(buf, buf.length, address, serverport);
socket.send(packet);
// get response
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
String received = new String(packet.getData(), 0, packet.getLength());
System.out.println(received);
socket.close();
}
}
import java.io.BufferedReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
class host
{
public static void main(String srgs[])
{
ServerSocket serverSocket = null;
Socket socket = null;
BufferedReader bufferedReader = null;
PrintStream printStream = null;
try{
serverSocket = new ServerSocket(0);
System.out.println("I'm waiting here: "
+ serverSocket.getLocalPort());
socket = serverSocket.accept();
System.out.println("from " +
socket.getInetAddress() + ":" + socket.getPort());
InputStreamReader inputStreamReader =
new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
String line;
while((line=bufferedReader.readLine()) != null){
System.out.println(line);
}
}catch(IOException e){
System.out.println(e.toString());
}finally{
if(bufferedReader!=null){
try {
bufferedReader.close();
} catch (IOException ex) {
System.out.print(ex.toString());
}
}
if(printStream!=null){
printStream.close();
}
if(socket!=null){
try {
socket.close();
} catch (IOException ex) {
System.out.print(ex.toString());
}
}
}
}
}
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class client {
public static void main(String args[])
{
if(args.length != 2){
System.out.println("usage: java client <port> <something>");
System.exit(1);
}
int port = isParseInt(args[0]);
if(port == -1){
System.out.println("usage: java client <port> <something>");
System.out.println("<port>: integer");
System.exit(1);
}
try{
//IP is hard coded, Local Loopback = "127.0.0.1"
//port is user entry
Socket socket = new Socket("127.0.0.1", port);
//Send msg to server
OutputStream outputStream = socket.getOutputStream();
PrintStream printStream = new PrintStream(outputStream);
printStream.print(args[1]);
socket.close();
}catch(UnknownHostException e){
System.out.println(e.toString());
}catch(IOException e){
System.out.println(e.toString());
}
}
private static int isParseInt(String str){
int num = -1;
try{
num = Integer.parseInt(str);
} catch (NumberFormatException e) {
}
return num;
}
}
original position |
aligned position |