본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

클라이언트 연결 3 import java.net.*; import java.io.*; import java.util.*; public class ChatServer { public static void main(String[] args) { try{ ServerSocket server = new ServerSocket(10001); System.out.println("접속을 기다립니다."); HashMap hm = new HashMap(); while(true){ //클라이언트 접속을 대기 Socket sock = server.accept(); ChatThread chatthread = new ChatThread(sock, hm); chatthread.start(); } // while }catch(Exception e){.. 더보기
클라이언트 연결 2 import java.io.*; import java.net.*; public class EchoClient { private String ip; private int port; private String str; BufferedReader file; public EchoClient(String ip, int port) throws IOException { this.ip = ip; this.port = port; Socket tcpSocket = getSocket(); OutputStream os_socket = tcpSocket.getOutputStream(); InputStream is_socket = tcpSocket.getInputStream(); BufferedWriter bufferW = ne.. 더보기
클라이언트 접속 import java.io.*; import java.net.*; public class EchoServer{ private BufferedReader bufferR; private BufferedWriter bufferW; private InputStream is; private OutputStream os; private ServerSocket serverS; public EchoServer(int port){ try{ serverS = new ServerSocket(port); }catch(IOException ioe){ ioe.printStackTrace(); System.exit(0); } while(true){ try{ System.out.println("클라이언트를 요청을 기다리는 중"); .. 더보기
10진수, 2진수, 8진수, 16진수로 쉽게 바꾸기 사실 형 변환 기초개념으로 구현 해야는데^^;; // 형변환. package Week1; public class Casting { public static void main(String[] args) { System.out.println("========================================="); System.out.println("10진수 2진수 8진수 16진수"); System.out.println("========================================="); for(int i=1;i 더보기
클래스 연습 (중요) public class Variable1 { int num; //인스턴스 변수 static int snum; // 클래스 변수 public void method(String s){ String st = s; //매개변수 s와 메서드내에 선언된 st는 로컬객체 } public void othermethod(){ System.out.println(++num); System.out.println(++snum); //System.out.println(st); // 로컬변수, 로컬객체는 참조 불가!!! } public static void main(String[] args) { // System.out.println(++num); // 인스턴스변수 직접 참조 불가 Variable1 v1= new Variable1.. 더보기