-
Socket coding
hey i'm using eclipse in one of my modules at university. i'm getting an error every time I run this code below. the error occurs on the socket. I've put the the errors in red can anyone help please
package UDP;
import java.net.DatagramPacket;
import java.net.InetAddress;
public class receivingUDP {
public static void main (String []args)throws Exception{
InetAddress address = InetAddress.getLocalHost();
int port = 8888;
byte[] buffer = new byte[256];
DatagramPacket packet =
new DatagramPacket(buffer, buffer.length,
address, port);
// Receive data
socket.receive(packet);
// Copy data from the packet to a String
String received =
new String(packet.getData(), 0,
packet.getLength());
System.out.println("Received: " +
received);
socket.close();
}
}
-
The error is because you've never actually declared and instantiated a Socket object. What is this class supposed to do?