Java 7일차 ServerSocket, Client 테스트

ServerSocketTest.java

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class ServerSocketTest
{
public static void main(String[] args)
{
try
{
Socket socket = null;

ServerSocket server = new ServerSocket(9000);

System.out.println("준비");
socket = server.accept();
System.out.println("준비완료");

Scanner sc = new Scanner(socket.getInputStream());

String data = sc.nextLine();

System.out.println(data);
}
catch(IOException e)
{
e.printStackTrace();
}
}

}

ClientTest.java

import java.io.PrintWriter;
import java.net.Socket;

public class ClientTest
{
public static void main(String[] args)
{
try
{
Socket client = new Socket("203.233.196.159", 9000);

String data = "Test";

PrintWriter pw = new PrintWriter(client.getOutputStream());

pw.println(data);
pw.flush();

pw.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

댓글 없음: