Results 1 to 2 of 2

Thread: Socket coding

  1. #1
    Neptunes07 is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default 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();
    }
    }

  2. #2
    marclurr is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    The error is because you've never actually declared and instantiated a Socket object. What is this class supposed to do?

Similar Threads

  1. Help with really simple coding
    By tigertomas in forum New To Java
    Replies: 10
    Last Post: 01-24-2009, 05:47 AM
  2. coding help
    By accies76 in forum New To Java
    Replies: 5
    Last Post: 11-12-2008, 09:15 PM
  3. Need help for coding and designing
    By g.ganiraju in forum New To Java
    Replies: 11
    Last Post: 11-01-2008, 05:49 AM
  4. Help On Coding problem
    By mandrake446 in forum New To Java
    Replies: 3
    Last Post: 12-08-2007, 08:01 AM
  5. Error in my coding
    By one198 in forum New To Java
    Replies: 2
    Last Post: 10-13-2007, 06:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •