글쓴이 :영준 1998년 6월 03일 15:53:13
안녕하세요...
네트웍 프로그램을 공부하면서 책에 있는 내용을
그대로 코딩을 했지요.
그런데, 서버측의 클래스와 클라이언트측의 클래스
2개가 있는데, 2개를 어떻게 연결 시켜 주어야할지를
모르겠군요 따로따로 컴파일하고 실행을 시키는지...
아니면 어떻게 ......
결과를 볼수 있는 방법을 알려주세요.
쏘쓰 한번 보시고 도와주세요...감사합니다.
public class SimpleServer {
public static void main(String args[]) {
ServerSocket s = null;
Socket s1;
String sendString = "Hello Net World!";
int slength = sendString.length();
OutputStream s1out;
DataOutputStream dos;
// Register your service on port 5432
try {
s = new ServerSocket(5432);
} catch (IOException e) { }
// Run the listen/accept loop forever
while (true) {
try {
// Wait here and listen for a connection
s1 = s.accept();
// Get a communication stream associated with the socket
s1out = s1.getOutputStream();
dos = new DataOUtputStream (s1out);
//Send your string!
dos.writeUTF(sendString);
// Cosde hte connection, but not the server socket
dos.close();
s1out.close();
s1.close();
} catch (IOException e) { }
}
}
}
******************************************************
import java.io.*;
import java.net.*;
public class SimpleClient {
public static void main(String args[]) throws IOExcption {
int c;
Socket s1;
InputStream s1In;
DataInputStream dis;
// Open your conneciton to sunbert, at port 5432
s1 = new Socket("sunbert", 5432);
// Get an input file handle from the socket and read the input
s1In = s1.getInputStream();
dis = new DataInputStream (s1In);
String st = new String (dis.readUTF());
System.ou.println(st);
//When done, just close the connection and exit
dis.close();
s1In.close();
s1.close();
}
}