프로젝트 발표가 끝나고...

우리조는 조원의 취업으로 인해서 프로젝트를 할때부터 좀 힘이 들었는데~

발표마저도 주말을 이용해서 따로 발표했어야 했다.. 사실 교수님 방에서

발표하는것도 부담이 되었던건 사실인데 어차피 맞아야 할 매라면 일찍

맞는게 더 괜찮은것 같았지만 늦게 발표해서 그나마 조금은 더 시간을 벌수 있어서

다행이라는 생각을 가지고 토요일에 교수님을 찾아뵈러 갔었던 것 같다.

교수님께서 음료두 사주시고 그래서 처음에 가지고 있었던 긴장감이나 이런것들이

조금은 사라지고 마음 편안하게 발표를 하였던것 같다 예상외로 발표는 프로젝트의

동작설명을 하는 것으로 끝이났다. 한편으로는 정말 다행이라는 생각이 들었다.

동작 설명 이후에 교수님께서 취업준비나 앞으로의 계획에 대한 질문을 하셔서

그것에 대한 답을 하고 교수님께서 상담을 해주셨다 앞으로 어떤 방식으로 해나가면

좋을지 등에 대한 답을 주셨는데 많은 도움을 교수님께 받은것 같습니다...........

그래서 난 우선은 취업을 한 이후에 학점인정을 해주는 자격증은 취득해 놓은것이

있으므로 토익 공부를 더 열심히 해서 일반 편입보다는 서울 산업대 야간 직장인들이

다니는 형식으로 편입을 하기로 마음을 먹었다. 이것 또한 쉬운 일은 아니겠지만

꼭 해야겠다, 매번 부모님께 기쁨보다는 실망 아쉬움이 많은 아들이니깐 이것만큼은

해서 부모님 바라시는거 해드리고 싶다. 머 마음으로야 더 좋은 대학 가구 싶지만 현실과

이상은 다른 법이니까요 ㅋㅋ 할수 있는 최선을 다해봐야겠다.........
 
최선을 다하고 그 결과에 실망하는건 도전조차 해보지 않은 사람보다는 좀더 괜찮은 사람이니깐

이상끝...

교수님 한 학기 동안 열심히 가르쳐 주셔서 감사합니다. 하지만 사실 제게는 너무 어려운 과목이라 

그런지 열심히는 하지 못했던것 같습니다. 그래도 제게 많은 도움이 된 수업이었습니다.

by 강창현 | 2008/12/12 16:45 | 시스템프로젝트 | 트랙백 | 덧글(1)

채팅 프로그램 프로젝트...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class Project{
  public static void main (String args[]){
   new LoginTitle();
    }
}
class LoginTitle extends JFrame implements ActionListener{
 private JTextField jtf1;
 private JPasswordField jtf2;
 public LoginTitle() {
 super("로그인");
 Container contentPane = getContentPane();    //Container를 가져온다.
 jtf1 = new JTextField(10);
 jtf1.setBorder(new TitledBorder("ID"));     //Border를 TitleBorder로설정
 jtf2 = new JPasswordField(10);
 jtf2.setBorder(new TitledBorder("PW"));     //Border를 TitleBorder로설정
        JButton b1= new JButton("회원가입"); b1.addActionListener(this);   //버튼객체 생성하고 액션리스너 추가
        JButton b2= new JButton("로그인"); b2.addActionListener(this);     //위와동일
 JPanel jp = new JPanel();
 jp.add(b1);jp.add(b2);
 contentPane.setLayout(new GridLayout(3,1));
 contentPane.add(jtf1);contentPane.add(jtf2);contentPane.add(jp);
 pack();
 setVisible(true);
 }
 public void actionPerformed(ActionEvent ae){
  String str=ae.getActionCommand();
  if(str.equals("회원가입")){
   new NewUser();
   setVisible(false);
  }
  else if(str.equals("로그인")){
   if(login()){
    new LoginSuccess(jtf1.getText());  //LoginSuccess객체를 메모리에 생성(인수는 ID값이 된다.)
    setVisible(false);
   }
  }
 }
 public boolean login(){
  boolean b=false;
  try{
   Class.forName("org.gjt.mm.mysql.Driver");
  }catch(ClassNotFoundException ee){}
  String url = "jdbc:mysql://127.0.0.1:3306/total";
  String id = "root";
  String pass = "dytc1234";
  String query = "select *from user where id='"+jtf1.getText()+"' and pw='"+jtf2.getText()+"'";
  try{
   Connection conn = DriverManager.getConnection(url,id,pass);
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery(query);
   b=rs.next();  //rs의 첫번째값이 있으면 true를 반환 첫번째값이 없으면 false를 반환
   rs.getString(1);
  }catch(SQLException ee){
   JOptionPane.showConfirmDialog(this,"ID또는 패스워드가 틀렸습니다.","오류",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE);
  }
 return b; 
 }
}
class NewUser extends JFrame implements ActionListener {//아이디, 비밀번호, 이름, 나이, 성별 
 private JTextField jt1,jt4,jt5;
 private JPasswordField jt2,jt3;
 private JRadioButton jr1,jr2;
 public NewUser() {
 super("회원가입");
        Container contentPane = getContentPane();
        jt1 = new JTextField(10);
 jt2 = new JPasswordField(10);
 jt3 = new JPasswordField(10);
 jt4 = new JTextField(10);
 jt5 = new JTextField(10);
 JButton jb1= new JButton("확인");jb1.addActionListener(this); //버튼객체 생성하고 액션리스너추가
        JButton jb2= new JButton("취소");jb2.addActionListener(this); //위와동일.
        jr1=new JRadioButton("남",true);
        jr2=new JRadioButton("여",false);
 ButtonGroup bg = new ButtonGroup();    //JRadioButton을 넣기위해 ButtonGroup객체 생성
 bg.add(jr1);bg.add(jr2);
 JPanel jp1 = new JPanel();JPanel jp2 = new JPanel();
 jp1.setLayout(new GridLayout(6,1));jp2.setLayout(new GridLayout(6,1));
 JPanel jp4 = new JPanel(); JPanel jp5 = new JPanel(); jp4.setLayout(new GridLayout(1,2));
 JPanel rbp = new JPanel();
 rbp.add(jr1);rbp.add(jr2);
 jp1.add(new JLabel("아이디 : "));jp1.add(new JLabel("비밀번호 : "));jp1.add(new JLabel("비밀번호확인 : "));jp1.add(new JLabel("이름 : "));
 jp1.add(new JLabel("나이 : "));jp1.add(new JLabel("성별 : "));
 jp2.add(jt1);jp2.add(jt2);jp2.add(jt3);jp2.add(jt4);jp2.add(jt5);jp2.add(rbp);jp4.add(jp1);jp4.add(jp2);
 jp5.add(jb1);jp5.add(jb2);
 contentPane.add(jp4,"Center");
 contentPane.add(jp5,"South");
 pack();
 setVisible(true);
        }
 public void actionPerformed(ActionEvent ae){
  String str =ae.getActionCommand();
  if(str.equals("취소")){
   setVisible(false);
   new LoginTitle();
  }
  else if(str.equals("확인")){
   if(!jt2.getText().equals(jt3.getText())){  //입력한 값두개가 일치하지 않을경우(비밀번호,재입력)
    JOptionPane.showConfirmDialog(this,"비밀번호가 같지않습니다.","오류",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE);
   }
   else{
   if(newUserDB()){
   new LoginTitle();
   setVisible(false);
   }
   }
  }
 }
 public boolean newUserDB(){
  String sex;
  boolean b=false;
  if(jr1.isSelected()){   //jr1(JRadioButton)이 선택되었으면 "남"을 String(s)에 저장
   sex = "남";
  }
  else{sex="여";}  //jr1(JRadioButton)이 선택되지 않았을때 "여"를 String(s)에 저장(JRadioButton을 두개사용하였으므로 하나로비교해도됨)
  try{  
       Class.forName("org.gjt.mm.mysql.Driver");
  }catch(ClassNotFoundException ee) {System.out.println("??");}
  String url = "jdbc:mysql://127.0.0.1:3306/total";
  String id = "root";
  String pass = "dytc1234";
  String update = "insert into user values('"+jt1.getText()+"','"+jt2.getText()+"','"+jt4.getText()+"',"+jt5.getText()+",'"+sex+"')";
  try{
   Connection conn = DriverManager.getConnection(url,id,pass);
   Statement stmt = conn.createStatement();
   stmt.executeUpdate(update);
   b=true;
   JOptionPane.showConfirmDialog(this,"회원가입이 완료되었습니다.","가입완료",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE);
  }catch(SQLException ee){b=false;
   JOptionPane.showConfirmDialog(this,"중복된 아이디가 있습니다..","오류",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE);}
   return b;
 }
}        
class LoginSuccess extends JFrame implements ActionListener,Runnable,KeyListener{
 private String id;
 private Socket s;
 private PrintWriter pw;
 private BufferedReader br;
 private JTextField tf;
 private JTextArea chatme;
 private Thread tr;
 private JScrollPane sp;
 public LoginSuccess(String s){
  super("채팅메인");
  id=s;  
  tr=new Thread(this);  //Thread객체 생성
  Container contentPane = getContentPane();
  newSocket();   //newSocket()메소드 실행
  tr.start();  //Thread시작
  chatme = new JTextArea(30,30);
  sp = new JScrollPane(chatme);  //Scroll을 charme객체에 추가
  JButton exit = new JButton("Logout");exit.addActionListener(this);   //버튼객체생성하고 액션리스너추가
  JButton send = new JButton("Send");send.addActionListener(this);     //위와동일
  tf = new JTextField(30);tf.addKeyListener(this);
  chatme.setEditable(false);   //내용 수정못하게 비활성화
  JPanel jp1 = new JPanel();
  jp1.add(send);jp1.add(exit);
  JPanel jp2 = new JPanel();
  jp2.setLayout(new BorderLayout());   //패널은 기본Layout이 Flow이기때문에 Border로 다시설정
  jp2.add(tf,"Center");jp2.add(jp1,"East");
  JPanel jp3 = new JPanel();
  jp3.add(sp,"Center");
  contentPane.add(jp3,"Center");contentPane.add(jp2,"South");
  pack();
  setVisible(true);
 }
 public void actionPerformed(ActionEvent ae){
  String str = ae.getActionCommand();   //이벤트가 발생된 객체의 커맨드값을 가져온다.
  if(str.equals("Logout")){
   setVisible(false);
   pw.println(id+"님이 접속을 종료하셨습니다.");  //메시지를 전송한다.
   pw.flush();pw.close();   //찌꺼기가남지않도록 flush를해주고 닫는다.
   try{s.close();}catch(IOException ee){System.out.print("오류없죠");}
   new LoginTitle();  //로그인타이틀객체를 메모리에 생성
  }
  else if(str.equals("Send")){
   send();
   tf.setText("");
  }
 }
 public void send(){ //입력된내용을 보내는 역할을 하는 메소드. ex) ID명> 안녕?
  String sen = id+"> "+tf.getText();
  pw.println(sen);
  pw.flush();
 }
 public void newSocket(){
  try{
  s=new Socket("127.0.0.1",8088);  //소켓을 생성 로컬호스트의 8088포트로
  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(s.getOutputStream())));
  br = new BufferedReader(new BufferedReader(new InputStreamReader(s.getInputStream())));
  pw.println(id);    //접속한사람의 id를 전송.
  pw.flush();
  pw.println(id+"님이 접속하셨습니다.");  //접속한 사람의 id와함께 메시지를 서버로 전송
  pw.flush();
  }catch(IOException ee){}
 }
 public void run(){   //멀티쓰레드를 이용하여 서버로부터 메시지를 받았을시 그것을 화면에 출력해준다.
  String str=null;
  try{
  while((str=br.readLine())!=null){
   chatme.append(str+'\n');   
  }
  }catch(IOException ee){}
 }
 public void keyPressed(KeyEvent e){   //키입력이 발생시 실행한다.
  if(e.getKeyCode() == KeyEvent.VK_ENTER) { // Enter키가 눌렸을때 실행된다.
   send();
   tf.setText("");
  }
 }
 public void keyReleased(KeyEvent e) {}  //인터페이스를 구현하였기때문에 그안의 내용을 모두 구현해야하기때문에. 써주었다.
 public void keyTyped(KeyEvent e) {}   //인터페이스를 구현하였기때문에 그안의 내용을 모두 구현해야하기때문에. 써주었다.
 
}

저희 조가 제출과 발표도 늦게하고 또 발표 끝나고 바로 기말고사가 이어지는 바람에 이렇게 늦게 올리게 되었습니다.
늦게 올린점 죄송합니다.

by 강창현 | 2008/12/11 20:30 | 시스템프로젝트 | 트랙백 | 덧글(0)

채팅 프로그램 서버 부분..

import java.io.*;
import java.net.*;
import java.util.*;
public class ProjectServer extends Thread{
 private ServerSocket ss;
 private Vector vc,iv;
 public ProjectServer(){
  vc=new Vector();
  iv=new Vector();
  newServer();
  start();
 }
 public void newServer(){
  try{
   ss=new ServerSocket(8088);  //서버소켓 객체 생성
   System.out.println("Server가 열렸습니다."); //메시지 출력
  }catch(IOException ee){System.out.println("서버를 열수없습니다.");}
 }
 public void run(){   //Thread를 사용하기위해.
  while(true){
  try{
   Socket s = ss.accept();   //서버에 클라이언트가 접속을 할경우 실행한다. (소켓을 계속생성하여준다).
   BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
   PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
   String a=br.readLine();   //받아온 메시지를 String a에 저장해준다.
   pw.flush();
   System.out.println(a+"님이 접속함");  //받은메시지를 출력.
   Id id = new Id(a); //id객체를 생성
   vc.add(s);  //벡터에저장.
   Multi m = new Multi(s,vc,id,iv);  //만들어진 Socket객체를 인수로받아서 Multi객체를 만들어준다. (각클라이언트마다 Thread를 실행해야하기때문에 이렇게 선언해주었다.)
  }catch(IOException ee){System.out.println("에러발생");}
  }
 }
 public static void main(String args[]){
  new ProjectServer();
 }
}
class Id {
 private String name;
 public Id(String id){  //String 변수를 인수로받는다.
  name=id;
 }
 public String getName(){return name;}
}
class Multi extends Thread{
 private Socket s=null;
 private PrintWriter pw;
 private BufferedReader br;
 private Vector vc,iv;
 private Id id;
 private boolean what;
 public Multi(Socket ss,Vector v,Id d,Vector i){
  what=true;
  s=ss;
  vc=v;
  iv=i;
  id=d;
  try{
  pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));   //서버로 송신하기위해 객체생성
  br=new BufferedReader(new InputStreamReader(s.getInputStream()));    //서버에서 수신하기위해 객체생성
  }catch(IOException ee){}
  start(); //Thread시작.
  
 }
 public void run(){
  String str=null;
  try{
  while((str=br.readLine())!=null){   //br.readLine()이 null값이 아닐경우 계속실행
   for(int i=0; i<vc.size(); i++){
    try{
    Socket soc = (Socket)vc.get(i);
    PrintWriter pw2 = new PrintWriter(new OutputStreamWriter(soc.getOutputStream()));
    if(what){  //처음실행하였는지 비교를한다. (처음일때)
     for(int j=0;j<iv.size();j++){
      Id addid = (Id)iv.get(j);
      pw2.println(addid.getName());
      pw2.flush();
     }
     pw2.println(str);
     pw2.flush();
     what=false;
    }
    else{   //처음이아닐경우.
     pw2.println(str);
     pw2.flush();
    }
    }catch(IOException ee){}
   }   
  }
  }catch(IOException ee){System.out.println(id.getName()+" 님이 접속끊음!!!");


  }
 }

}

by 강창현 | 2008/12/11 20:25 | 시스템프로젝트 | 트랙백 | 덧글(0)

화이트 보드

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Study1117_3 extends Frame{

 private MyCanvas mc;
 private MenuPanel pane;
 private Pen p;// 각 다른 클래스들 선언
 public Study1117_3(){
  
  super("도형그리기-화이트보드");
  p = new Pen();
  mc = new MyCanvas(p);
  pane = new MenuPanel(p,mc);//객체를 생성해주고 펜객체를 사용하기위해
     // 각객체에 p를 인수로 전달한다.
     // 메뉴패널에는 다지우기버튼을 위한 캔버스객체까지 전달.  

  setSize(800,600);
  add(pane,"West");
  add(mc,"Center");
  setVisible(true);
  
 }
 
 public static void main (String args[]){
  Study1117_3 obj = new Study1117_3();
 }
 
 
}

class Pen{
 
 private int type = 0;
 
 public void setType(int type){
  
  this.type = type;
  
 }
 
 public int getType(){
  return type;
 }
 
 
}//버튼을 어떤버튼을 눌럿는지 버튼에 맞는 번호를 저장하고, 반환.

class MenuPanel extends Panel{

 private Pen p;
 private MyCanvas mc;
 
 public MenuPanel(Pen p, MyCanvas mc){
  super(new GridLayout(8,1));
  this.p = p;
  this.mc = mc;
  Button b1 = new Button("사각형");
  Button b2 = new Button("삼각형");
  Button b3 = new Button("둥근사각형");
  Button b4 = new Button("동그라미");
  Button b5 = new Button("부채꼴");
  Button b6 = new Button("직선");
  Button b7 = new Button("지우기");
  Button b8 = new Button("모두 지우기");//버튼생성.
  MenuListener ml = new MenuListener(p, mc);//리스너객체생성인수로 Pen객체 전달.
       //또한, 다지우기를 해야하므로
       //MyCanvas 객체까지 같이 전달.
  b1.addActionListener(ml);
  b2.addActionListener(ml);
  b3.addActionListener(ml);
  b4.addActionListener(ml);
  b5.addActionListener(ml);
  b6.addActionListener(ml);
  b7.addActionListener(ml);
  b8.addActionListener(ml);//각버튼에 액션리스너 add
  add(b1);
  add(b2);
  add(b3);
  add(b4);
  add(b5);
  add(b6);
  add(b7);
  add(b8);//패널에 버튼 삽입.
 }
 
 
}

class MenuListener implements ActionListener{
 
 private Pen p;
 private MyCanvas mc;
 
 public MenuListener(Pen p, MyCanvas mc){
  this.p = p;
  this.mc = mc;//인수로 전달된 Pen 객체 저장.
 }
 
 public void actionPerformed(ActionEvent e){
  
  String str = e.getActionCommand();
  if ("사각형".equals(e.getActionCommand())){
   p.setType(1);
  }
  else if ("삼각형".equals(e.getActionCommand())){
   p.setType(2);
  }  
  else if ("둥근사각형".equals(e.getActionCommand())){
   p.setType(3);
  } 
  else if ("동그라미".equals(e.getActionCommand())){
   p.setType(4);
  } 
  else if ("부채꼴".equals(e.getActionCommand())){
   p.setType(5);
  } 
  else if ("직선".equals(e.getActionCommand())){
   p.setType(6);
  } 
  else if ("지우기".equals(e.getActionCommand())){
   p.setType(7);
  }
  //각 도형에 맞는 번호를 인수로 Pen객체에 전달. 
  else if ("모두 지우기".equals(e.getActionCommand())){
   Graphics g = mc.getGraphics();
      g.clearRect(0,0,mc.getWidth(),mc.getHeight());
  }//my를 이용하여 전체화면을 클리어. 
  
  
  
  
 }
 
}

class MyCanvas extends Canvas{
 
 private Pen p;
 private int xp, yp, xr, yr;
 private int lx, ly, dwid, dhei, sx, sy;

 public MyCanvas(Pen p){
  
  this.p = p;
  addMouseListener(new MouseAdapter(){
   
   public void mousePressed(MouseEvent e){
    xp = e.getX();
    yp = e.getY();//클릭할때의 좌표점 저장.
   }
   
   public void mouseReleased(MouseEvent e){
    xr = e.getX();
    yr = e.getY();//땔때의 좌표점 저장.
    draw();//마우스버튼을 땟을때 바로 도형이 생기기 위해.
   }
   
  });
 }
 
 public void paint(Graphics g){
 }//도형을 그리고 백터에 저장하는 메서드가 있다면
 //여기서 그 백터의 정보를 불러와서
 //화면이 줄거나 커지거나 하는 캔버스 크기의 변화가 생겨도
 //도형이 계속 남아있을수 있다.
 
 public void draw(){
  
  Graphics g = getGraphics();
  if(xp > xr){
   dwid = xp - xr;
      lx = xp;
      sx = xr;
    }
  else if(xp < xr){
      dwid = xr - xp;
      lx = xr;
      sx = xp;
    }
  else if(xp == xr){
      dwid = 0;
      lx = xp;
      sx = xp;
    }
    if(yp > yr){
      dhei = yp - yr;
      ly = yp;
      sy = yr;
    }
  else if(yp < yr){
      dhei = yr - yp;
      ly = yr;
      sy = yp;
    }
  else if(yp == yr){
      dhei = 0;
      ly = yp;
      sy = yp;
    }//각좌표점이 항상 먼저 찍히는 쪽이 좌측 위가 아니므로,
  //그것을 대비한 좌표점 저장을 위해 도형이 그려질 좌표점 지정.
  
  switch(p.getType()){
   case 1:
        g.drawRect(sx, sy, dwid, dhei);
        break;
      case 2:
        int[] xpos = {sx, (xp+xr)/2, lx};
        int[] ypos = {ly, sy, ly};
        g.drawPolygon(xpos, ypos, 3);
        break;
      case 3:
        g.drawRoundRect(sx,sy,dwid,dhei,5,10);
        break;
      case 4:
        g.drawOval(sx,sy,dwid,dhei);
        break;
      case 5:
        g.fillArc(sx,sy,lx,ly,0,160);
        break;
      case 6:
        g.drawLine(sx,sy,lx,ly);
        break;
      case 7:
        g.clearRect(sx,sy,lx,ly);
        break;
    }//각 버튼이 눌려질때 Pen 객체에 저장된 번호를 보고
  // 그 번호에 맞도록 도형이 그려지겠금 스위치문 사용.
  //발전방향 - 이다음에 벡터에 방금 그린 도형의 정보를 저장하여
  // paint 메서드에서 그 벡터 정보를 읽어와 다시 그려주는 혹은
  // 그 횟수에 맞도록 루프를 돌리는 이것과 같은 메서드를 한개더 만들어
  // 캔버스의 크기조절에도 대처할수 있도록 하는 것이 필요.
-------------------------------------------------------------------
프로젝트 관련된것 프로젝트 제출일 전으로 올리도록 하겠습니다.
제가 잘 하지 못해서 친구한테 배워가면서 구현해야 해서 시간이 조금 오래 걸립니다.
죄송합니다. 열심히 가르쳐 주시는데 제가 잘 알아듣지를 못해서요~ㅠㅠ
교수님 그리고 파트너 친구가 취업관계로 퇴근 시간이 너무 늦는 바람에
발표는 참여 못할수도 있다고 합니다. 시험에만 회사를 비울수 있다고 해서요..
이 경우는 어찌 해야 하나요?
  

by 강창현 | 2008/11/25 22:16 | 시스템프로젝트 | 트랙백 | 덧글(1)

자바 수업내용..

*서버쪽 구현*
import java.net.*;
import java.io.*;

class Server extends Thread{
 
 private Socket clnt;
 private BufferedReader in;
 private PrintWriter out;
 private String str = null;
 
 public Server(Socket clntSocket){
  
  clnt = clntSocket;
  try{
   in = new BufferedReader
    (new InputStreamReader(clnt.getInputStream()));
   out = new PrintWriter(clnt.getOutputStream(),true);
  }catch(IOException e){
   System.out.println(e.getMessage());
  }
 }
 public void run(){
  
  try{
   str = in.readLine();
   System.out.println(str+"을 수신");
   System.out.println("클라이언트 재전송");
   out.println(str);
   clnt.close();
  }catch(IOException e){
   System.out.println(e.getMessage());
    }
   }
 }


public class Study1119_1 {

 static ServerSocket servSocket;
    static Socket clntSocket;
    public static void main (String args []){
  

  
  try{
   servSocket = new ServerSocket(9000);
   System.out.println("메세지수신기다림");
   while(true){
    clntSocket = servSocket.accept();
    Thread sv = new Server(clntSocket);
    sv.start(); 
    }

  }catch(IOException e){
   System.out.println(e.getMessage());
    }
   }
 }
---------------------------------------------------------------
*클라이언트쪽 구현*
import java.net.*;
import java.io.*;


public class Study1119_2 {
 static Socket csocket;
 public static void main(String args[]){
  
  try{
   csocket = new Socket(args[0], Integer.parseInt(args[1]));
      System.out.println(args[0]+" "+args[1]+"서버 접속");
   BufferedReader in = new BufferedReader(new
            InputStreamReader(csocket.getInputStream()));
      PrintWriter out = new PrintWriter(csocket.getOutputStream(),true);
      BufferedReader reader = new BufferedReader(
      new InputStreamReader(System.in));
      String str = reader.readLine();
      out.println(str);
      System.out.println("서버로 메세지를 전송");
      String instr = in.readLine();
      System.out.println("서버가 메세지 -"+instr+"-  받았습니다. ");
      csocket.close();
  }catch(IOException e){
   System.out.println(e.getMessage());
   }
  }
}

by 강창현 | 2008/11/24 23:46 | 시스템프로젝트 | 덧글(1)

◀ 이전 페이지          다음 페이지 ▶