السلام عليكم
مساء الخير
أنا عندى برنامج وعندى بعض التعديلات حولات بس فى أخطاء
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();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);
}
}
}
}
}هذى المطلوب تنفيذه على البرنامج.
Write a client server application using Java sockets that allows a client to write a message (as a String) to a socket. A server will read this message, count the number of characters and digits in the message, and send these two counts back to the client. The server will listen to port 6100. The client can obtain the String message that is to pass to the server either from the command line or by using a prompt to the user. One Strategy for sending the two counts back to the client is for the server to construct an object containing: a) The message it receives from the client b) A count of the number of characters in the message c) A count of the number of digits in the message The server will read the String from the socket, construct a new object that implements the Message interface, count the number of characters and digits in the String, and write the content of the Message object to the socket. The client will send a String to the server and will wait for the server to respond with a message containing the count of the number of characters and digits. Communication over the socket connection will require obtaining the InputStream and OutputStream for the socket. Objects that are written to or read from an OutputStream or InputStream must be serialized and therefore must implement the java.io.Serializable interface. Please, design a class named MessageImpl that implements both java.io.Serializable and the Message interface. Serializing an object requires obtaining a java.io.ObjectOutputStream and then writing the object using the writeObject() method in the ObjectOutputStream class. Thus, the server’s activity will be organized roughly as follows: a) Reading the String from the socket b) Constructing a new MessageImpl object and counting the number of characters and digits in the message c) Obtaining the ObjectOutputStream for the socket and writing the MessgaeImpl object to this output stream. Reading a serialized object requires obtaining a java.io.ObjectIntputStream and then reading the serialized object using the readObject() method in the ObjectInputStream class. Therefore, the client’s activity will be arranged approximately as follows: a) Writing the String to the socket b) Obtaining the ObjectInputStream from the socket and reading the MessageImpl.
أرجو المساعدتكم وتضيح
وشكرا.


