Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Can someone help me with this project - willing to pay (and has to be done in the next hour)

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can someone help me with this project - willing to pay (and has to be done in the next hour)

    I have to write a client and server class for a UDP protocol sending integer numbers by UDP packets. So far i have this;

    Client Code:

    import java.io.*;
    import java.net.*;

    class UDPClient {
    public static void main(String args[]) throws Exception {

    BufferedReader inFromUser =
    new BufferedReader(new InputStreamReader(System.in));

    DatagramSocket clientSocket = new DatagramSocket();

    InetAddress IPAddress = InetAddress.getByName("hostname");

    byte[] sendData = new byte[1024];
    byte[] receiveData = new byte[1024];

    String sentence = inFromUser.readLine();
    sendData = sentence.getBytes();

    DatagramPacket sendPacket =
    new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

    clientSocket.send(sendPacket);

    DatagramPacket receivePacket =
    new DatagramPacket(receiveData, receiveData.length);

    clientSocket.receive(receivePacket);

    String modifiedSentence =
    new String(receivePacket.getData());

    System.out.println("FROM SERVER:" + modifiedSentence);
    clientSocket.close();
    }
    }

    Server Code:

    import java.io.*;
    import java.net.*;
    class UDPServer {
    public static void main(String args[]) throws Exception
    {
    DatagramSocket serverSocket = new DatagramSocket(9876);
    byte[] receiveData = new byte[1024];
    byte[] sendData = new byte[1024];
    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();
    String capitalizedSentence = sentence.toUpperCase();
    sendData = capitalizedSentence.getBytes();
    DatagramPacket sendPacket =
    new DatagramPacket(sendData, sendData.length, IPAddress,
    port);
    serverSocket.send(sendPacket);
    }
    }
    }

    But i now need to change this so that:

    The client;

    1. Reads an integer from keyboard input and stores its value in a UDP packet. // byte[] send = ByteBuffer.allocate(4).putInt(num).array(); ???
    2. Sends the UDP packet to the server, on port number 1999;
    3. Listens for UDP packets from the server (until it receives a packet with a non-positive number; see
    step (b) below). While listening:
    (a) Once it receives a UDP packet from the server, it subtracts 2 from the integer value num contained
    in it. // int num = ByteBuffer.wrap(receive).getInt(); ???
    (b) Checks the integer value num: if the value is greater than 0 (num>0) then the client stores it in a
    new UDP packet and sends the packet to the server; otherwise (num<=0) the client terminates.

    The Server;

    1. Listens on port 1999;
    2. For each UDP packet it receives from a client:
    (a) extracts the integer value n contained in it;
    (b) decreases the value of n by 2;
    (c) sends back to the client a UDP packet containing the new value of n.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can someone help me with this project - willing to pay (and has to be done in the next hour)

    Please post your code correctly.

Similar Threads

  1. Problem to get hour and minute
    By sassa44000 in forum Android Development
    Replies: 9
    Last Post: March 30th, 2014, 09:56 AM
  2. URGENT HELP NEEDED IN AN HOUR:Printing first number in input
    By Java girl in forum What's Wrong With My Code?
    Replies: 16
    Last Post: March 22nd, 2014, 10:47 AM
  3. URGENT! Due in one hour. Please help!
    By imanoob in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 10th, 2013, 11:25 AM
  4. Rush hour game
    By zerocos in forum What's Wrong With My Code?
    Replies: 46
    Last Post: January 25th, 2013, 06:05 PM
  5. Help with Clock (advance and reverse day,hour,minute)
    By whyld4900 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 13th, 2011, 02:39 AM

Tags for this Thread