0
Can anyone help me with problem server_client...
write a code,like client send two numbers to server .server accept it do adding on that two numbers and send back result of like 2+2..return result 4 in textArea...tnx
4 Answers
0
This exemple implements a client that connects to a server, a simple way using the Socket class.
String hostName = args[0];
int portNumber = Integer.parseInt(args[1]);
try (
Socket echoSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader( new InputStreamReader(echoSocket.getInputStream()));
BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in))
)
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}
Oracle docs:
https://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html
0
is this just a server or both server and client??....i need ti ad it in frame to client side to have a field text area where is server deliver a result and must have a button that when you enter two numbers in other two field you click it and send that numbers to server and server do that adding and return it to client on text area...
0
Maybe you should use RMI, it's API for remote method invocation.
0
i must use AWT controls and layouts..i know that.but i dont know how to add a logic in that textFields and in button for sending.