Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package SocketProgramming3_ECHO;
- import java.io.IOException;
- import java.net.Socket;
- import java.io.*;
- /**
- *
- * @author acer
- */
- public class Client {
- private static final String SERVER_IP="localhost";
- private static final int SERVER_PORT=9090;
- public static void main(String[] args) throws IOException {
- System.out.println("[Client] Client Started");
- Socket client=new Socket(SERVER_IP,SERVER_PORT);
- /////////////////getting input from user//////////////////////////////////////////
- System.out.println("[Client]: enter a string ");
- BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
- String input=userInput.readLine();
- ///////////////////sending request through socket/////////////////////////////
- PrintWriter out=new PrintWriter(client.getOutputStream(),true);
- out.println(input);
- ///////////////////Getting reply from socket/////////////////////////////
- BufferedReader ServerReplyInput=new BufferedReader(new InputStreamReader(client.getInputStream()));
- String ServerReply=ServerReplyInput.readLine();
- System.out.println("[Server]"+ServerReply);
- client.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement