Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.Scanner;
- public class Server{
- public static void main(String argv[]) throws Exception
- {
- /*1.connection*/
- ServerSocket serverSocket = new ServerSocket(6789);
- Socket connectionSocket = serverSocket.accept();
- /*2. reading from the socket using scanner or BufferedReader*/
- Scanner scanner = new Scanner(connectionSocket.getInputStream());
- //read
- String clientSentence = scanner.nextLine();
- System.out.println("Received: " + clientSentence);
- /*3. modification of the sentence*/
- String modifiedSentence =clientSentence.toUpperCase();
- /*4. writing in the socket*/
- DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
- outToClient.writeBytes(modifiedSentence+ 'n');
- scanner.close();
- connectionSocket.close();}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement