Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Server
- import java.io.*;
- import java.net.*;
- public class Server {
- public static void main(String[] args) throws IOException {
- ServerSocket ss = new ServerSocket(1201);
- Socket s = ss.accept();
- DataInputStream din = new DataInputStream(s.getInputStream());
- DataOutputStream dout = new DataOutputStream(s.getOutputStream());
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String msgin="", msgout = "";
- while(!msgin.equals("end")) {
- msgin = din.readUTF();
- System.out.println(msgin);
- msgout = br.readLine();
- dout.writeUTF(msgout);
- dout.flush();
- }
- s.close();
- }
- }
- // Client
- import java.io.*;
- import java.net.*;
- public class Client {
- public static void main(String[] args) throws IOException {
- Socket s = new Socket("127.0.0.1",1201);
- DataInputStream din = new DataInputStream(s.getInputStream());
- DataOutputStream dout = new DataOutputStream(s.getOutputStream());
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String msgin="", msgout="";
- while(!msgin.equals("end")){
- msgout = br.readLine();
- dout.writeUTF(msgout);
- msgin = din.readUTF();
- System.out.println(msgin);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement