병렬 송수신 질문이요 ㅠㅠ
갅지돋는슬아
아래의 프로그램은 에코서버 프로그램을 켜놓으면 에코클라이언트 프로그램에서 입력을 해서
에코서버 프로그램이 받는 프로그램입니다.
여기서 제가 원하는건 서로가 송수신이 되는 병렬 프로그램인데요.
에코서버와 에코클라이언트, 둘다 어느 한쪽에서 입력을 하면 다른한쪽이 받게 되는 프로그램을 짜고 싶은데
아무리 머리를 굴려봐도모르겠어서 부탁드립니다 ㅠ
서로가 송수신이 되는 병렬프로그램이면서 둘다 한쪽에서 입력을 받으면 다른한쪽에서 출력을 했음하네요.내공100걸께요 ㅠㅠ. 빠른답변 부탁드립니다.
프로그램옆에 설명도 같이 붙여주시면 감사합니다 !
--------------------------------------------------------------------------------------------
import java.net. *;
import java.io.*;
public class EchoClient {
private Socket socket;
public EchoClient(String host, int port) throws Exception {
socket=new Socket(host, port);
}
public void echo() throws IOException {
OutputStreamos=socket.getOutputStream();
InputStreamis=socket.getInputStream();
BufferedReaderin=new BufferedReader ( new InputStreamReader(is));
PrintWriterout=new PrintWriter(os, true);
BufferedReadercon=new BufferedReader ( new InputStreamReader(System.in));
while(true) {
String msg=con.readLine();
out.println(msg);
if (msg.equals(bye))
break;
System.out.println(in.readLine());
}
}
public void close() throws IOException {
socket.close();
}
public static void main(String[] args) {
try{
EchoClientec;
System.out.println(Input Message);
if(args.length 0)
ec=new EchoClient(args[0], 5000);
else
ec=new EchoClient(localhost, 5000);
ec.echo();
ec.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------------------------------------
import java.net. *;
import java.io.*;
public class EchoServer {
private ServerSocket server;
public EchoServer(int port) throws Exception {
server=new ServerSocket(port);
}
public void services() throws IOException {
System.out.println(EchoServer is ready.);
Socket client=server.accept();
InputStreamis=client.getInputStream();
OutputStreamos=client.getOutputStream();
BufferedReaderin=new BufferedReader ( new InputStreamReader(is));
PrintWriterout=new PrintWriter(os, true);
while(true) {
String msg=in.readLine();
System.out.println(msg);
if (msg.equals(bye))
break;
out.println( + msg);
}
}
public void close() throws IOException {
server.close();
}
public static void main(String[] args) throws Exception {
try{
EchoServeres=new EchoServer(5000);
es.services();
es.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------------------------------------