Server


~cpp 
import java.net.*;
import java.io.*;

public class ServerSocketTest implements Runnable {

	ServerSocket server;
	
	
	public ServerSocketTest() throws IOException {

		server = new ServerSocket(22500);

	}

	public static void main(String[] args) {

		try {
			
			ServerSocketTest sst = new ServerSocketTest();
			
			new Thread(sst).start();
			
		} catch (IOException ioe) {
			
			System.err.println("실행할 수 없습니다.");
			ioe.printStackTrace();
			
		}
	}
	
	public void run() {

		try {

			Socket connect;
				
			System.out.println("서버에서 접속을 기다립니다.");
			connect = server.accept();
			
			System.out.println("접속되었습니다.");
			System.out.println(connect.getInetAddress());
									
						
			while (true) {
				if ( connect.isBound() ) {
					System.out.println("종료되었습니다.");
					break;
				}
			}
			
			connect.close();
				
		} catch (Exception e) {
			
			System.out.println("예외가 발생하였습니다.");
			e.printStackTrace();
			
		}
	}
}

Client


~cpp 
import java.net.*;
import java.io.*;

public class SimpleSocketTest {
	
	public static void main(String[] args) throws Exception {
		
		String a =  "165.194.17.86";

		Socket socket = new Socket(a, 22500);
		
		socket.close();

	}
}
Retrieved from http://wiki.zeropage.org/wiki.php/Server&Client/상욱
last modified 2021-02-07 05:28:00