Menu

[Solved]-Udpserverjava Import Javaioioexception Import Javanetdatagrampacket Import Javanetdatagram Q37192764

Keyword: UDP Socket, Client - Server You are to write a UDP connectionless client-server pair in the language of your choice.//UDPServer.java

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPServer {
   public static void main(String[] args) throwsIOException {
      
       try {
           DatagramSocketds = new DatagramSocket(5432);
          
           byte[] buf = newbyte[1024];
           DatagramPacketdp = new DatagramPacket(buf, buf.length);
          
          ds.receive(dp);
          
           byte[] data =dp.getData();
           int length =dp.getLength();
           InetAddressipClient = dp.getAddress();
           int port =dp.getPort();
          
           String str = newString(data, 0, length);
          System.out.println(“Server received:”+str);
          
           String dataout =”Hello-Don’t eat yellow snow”;
           DatagramPacketdpout = new DatagramPacket(dataout.getBytes(), dataout.length(),ipClient, port);
          ds.send(dpout);
          
          ds.close();
          
       } catch (SocketException e) {
           // TODOAuto-generated catch block
          e.printStackTrace();
       }
      
      
   }
}

//UDPClient.java

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

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

       try {
           DatagramSocketds = new DatagramSocket();
          
           String data =”Hello”;
           DatagramPacketdp = new DatagramPacket(data.getBytes(), data.length(),InetAddress.getLocalHost(), 5433
                             );
          ds.send(dp);
          
           byte[] buf = newbyte[1024];
           DatagramPacketdpIn = new DatagramPacket(buf, buf.length);
          ds.receive(dpIn);
          System.out.println(new String(dpIn.getData(), 0,dpIn.getLength()));
          
          ds.close();
          
       } catch (SocketException e) {
           // TODOAuto-generated catch block
          e.printStackTrace();
       } catch (IOException e) {
           // TODOAuto-generated catch block
          e.printStackTrace();
       }
   }
}

Here is my code so far. I don’t know how to make Server returnport 5433. please help.

Keyword: UDP Socket, Client – Server You are to write a UDP connectionless client-server pair in the language of your choice. The client will send a UDP message to the server, e.g. “Hello”. The server will start and run on port number 5432 and return the original message concatenated with a humorous message as an ASCII string to the client on port 5433. The client will then present a formatted string to the monitor As an example, the basic output should look like: Your client program sends “Hello” Your client program would receive the string “Hello – Don’t eat yellow snow” from the server. Please feel free to choose any programming language, on any operating system Show transcribed image text Keyword: UDP Socket, Client – Server You are to write a UDP connectionless client-server pair in the language of your choice. The client will send a UDP message to the server, e.g. “Hello”. The server will start and run on port number 5432 and return the original message concatenated with a humorous message as an ASCII string to the client on port 5433. The client will then present a formatted string to the monitor As an example, the basic output should look like: Your client program sends “Hello” Your client program would receive the string “Hello – Don’t eat yellow snow” from the server. Please feel free to choose any programming language, on any operating system

Expert Answer


Answer to //UDPServer.java import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *