Question

Overview UDP is a transport layer protocol that provides no reliability. This project aims to show...

Overview

UDP is a transport layer protocol that provides no reliability. This project aims to show how to implement extra features for the protocol in the application layer. The project will develop a new version of UDP protocol called UDPplus which provides reliable connection oriented between a client and a UDPplus sever. The UDPplus is implemented at application layer using UDP protocol only.

Basic Scenario

The UPDplus is a simple bank inquiry application where the client sends full name and receive the account name that is associated with this name as following

Name

Account No

Abdullah Ali

15324

Manal Abdullah

90781

Henry Markos

88125

Hisham Mansoor

62044

Client Process: the process reads the name from a user then sends it to the server which returns the account number. The process prints the account number to the user.

Server Process: the process remains ready to receive inquiries, once an inquiry is received it looks for the account associated with the name as it is showed in the table above. If the account is found the process returns the account number or returns “0000” as an error. III. Application Core Features

The basic scenario should be extended to implement the following features:

  1. Connection oriented feature: the UPDplus should implement two way handshaking. The client should send a notification to the server in order to establish a new connection. If the server is available it will replay with the maximum number of messages the server can handle. If the server is not available (i.e. busy), it will replay with -1.
    1. You should implement the server to randomly response with a chance 20% not available.
    2. The client cannot send datagrams until a positive response received from the server.
    3. The port number for the server side is 9152.
    4. The port number for the client side should be random.

      server code

    5. package se;

      import java.io.*;

      import java.net.*;

      class Server {

        

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

              System.out .printf("Server Runing ");

              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);

              }

          }

        }

client code

package se;

import java.io.*;

import java.net.*;

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

    System.out.printf("client Runing :");

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

    DatagramSocket clientSocket = new DatagramSocket();

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

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

   

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Server Code

import java.io.*;

import java.net.*;

class Server {

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

        System.out .println("Server Runing ");

        DatagramSocket serverSocket = new DatagramSocket(9876);

        byte[] receiveData = new byte[1024];

        byte[] sendData = new byte[1024];
        int i;
        int ans = 0;
        String name[] = new String[]{ "Abdullah", "Manal","Henry","Hisham"};
        String acc[] = new String[] {"15324","90781","88125","62044"};

        while(true) {

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

            serverSocket.receive(receivePacket);

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

            InetAddress IPAddress = receivePacket.getAddress();
            int port = receivePacket.getPort();
      
            for(i=0; i<4; i++)
            {
                String tmp = name[i];

                if(sentence.equals(tmp)==true)
                {
                    String capitalizedSentence = acc[i];
                    sendData = capitalizedSentence.getBytes();
                    DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
                    serverSocket.send(sendPacket);
                    ans = 1;
                }
            }
            if(ans==0)
            {
                String err="0000";
                sendData = err.getBytes();
                DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
                serverSocket.send(sendPacket);
            }
        }

    }

}

client code

import java.io.*;

import java.net.*;

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

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

    DatagramSocket clientSocket = new DatagramSocket();

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

    byte[] sendData = new byte[1024];

    byte[] receiveData = new byte[1024];

    System.out.println("Enter Name Of Customer");
    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("Account Number is :" + modifiedSentence);
  
    clientSocket.close();

}

}

Add a comment
Know the answer?
Add Answer to:
Overview UDP is a transport layer protocol that provides no reliability. This project aims to show...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following Client side Java code can send a message to the server side via UDP...

    The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks with...

  • Q7 The following Client side Java code can send a message to the server side via...

    Q7 The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks...

  • Using Eclipse I am trying to pass a string of numbers from the client class to...

    Using Eclipse I am trying to pass a string of numbers from the client class to the server. The server will then compute the sum, average max and min from the numbers and then pass it back to the client. The client will then display the answers in a text field. This is what i have so far for the class client and not sure how to proceed or if it's correct. i also am not sure how to complete...

  • I need help with this assignment, please; Programming Assignment 3: UDP Pinger Lab In this lab,...

    I need help with this assignment, please; Programming Assignment 3: UDP Pinger Lab In this lab, you will study a simple Internet ping server written in the Java language, and implement a corresponding client. The functionality provided by these programs is similar to the standard ping programs available in modern operating systems, except that they use UDP rather than Internet Control Message Protocol (ICMP) to communicate with each other. (Java does not provide a straightforward means to interact with ICMP.)...

  • I have to modify a server program and chat program to work as the following instructions...

    I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT