I recently have had a class that has me running java programs from the command line and I seem to have the problem of the cmd not finding the main class
I have installed java correctly, java and javac commands come up with the respective menus. No issues come up when I press javac UDPServer.java, however if I press java UDPServer, I get the error. Any suggestions?
import java.io.*;
import java.net.*;
import java.util.*;
class UDPServer {
public static void main(String args[]) throws Exception
{
InetAddress srvIP = InetAddress.getByName("192.168.1.3");
DatagramSocket serverSocket = new DatagramSocket(5000,srvIP);
byte[] receiveData = new byte[64]; byte[] sendData = new byte[64];
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
Calendar rightNow = Calendar.getInstance();
sendData = rightNow.getTime().toString().getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
serverSocket.send(sendPacket);
}
}
}
Also, another quick question: I am running an Ubuntu VM and I have to run a Server.java program on my host and a Client.java on my VM. When I try to configure the IP addresses. I'm not sure what to put, there are two: Ethernet adapter Virtual-Box and Ethernet Adapter Local Area Connection. To connect the two programs, which should I use?\
Thanks in advance
java -cp . UDPserver- it's possible you need to put the current directory in the classpath.