가 하고싶은게 버스기사 위치정보를 서버에 전송을하고

그 서버에서 사용자가 위치정보를 볼수있게 하고싶은 프로그래밍을 하고있어요..ㅠ


지금은 서버코드랑 운전자코드만하면 데이터는 잘 송수신되는데

서버코드랑 승객코드는 데이터송수신이 않됩니다;;


근데 서버코드에 있는

Data Data socket);
    data.recive();//with dri
    data.send();

이거의 recive랑 send위치를 바꾸면 반대로 안되구요..


제가 java 소켓통신은 처음이라서그런데 정말 부족한게 많아보이실껍니다..

제발좀 도와주세요 ㅠㅠ





-----------------서버코드

public class Ser {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  ServerSocket serversocket = null;
  try{
   serversocket=new ServerSocket(7777);
   while(true) //멀티 쓰레딩
    {
    Socket socket =serversocket.accept();
    
    Data Data(socket);
    data.recive();//with dri
    data.send();
   }
  }catch(IOException ioe){
   System.err.println("Exception");
  } finally{
   try{
    serversocket.close();
   }catch(IOException ignored){}
  }
 }
}

class Data extends Thread{
 protected Socket socket;
 public String location="aaa";
 public Data(Socket socket){
  this.socket=socket;
 }
 public void recive(){
  try{
   BufferedReader reader=new BufferedReader(new InputStreamReader(socket.getInputStream()));
   location=reader.readLine();
   System.out.println("받은정보"+location);//console화면 출력
   
  } catch (IOException ignored) {
  }
  finally{
   try{
    socket.close();
   } catch(IOException ignored){}
  }
 }
 public void send(){
  try{
   BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
   writer.write(location); //location정보를 pas에 보냄
      writer.flush();
      System.out.println("보낸정보"+location);//console화면 출력
  }catch (IOException ignored) {
  }
  finally{
   try{
    socket.close();
   } catch(IOException ignored){}
  }
 }
}




--------------드라이버코드

public class Dri {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String location="123123";
  Socket socket=null;
  try{
   socket=new Socket("127.0.0.1",7777);
   BufferedWriter writer = new BufferedWriter(
     new OutputStreamWriter(socket.getOutputStream()));
   
   writer.write(location);//위치정보를 서버로 보냄
   writer.flush();
   
   System.out.println("보낸정보"+location);//console화면 출력
  }catch(IOException ioe){
   System.err.println("Exception");
  }finally{
   try{
    socket.close();
   }catch(Exception ignored){}
  }
 }
}



------------승객코드

public class Pas {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String location="asd";
  Socket socket=null;
  try{
   socket=new Socket("127.0.0.1",7777);
   BufferedReader reader = new BufferedReader(
     new InputStreamReader(socket.getInputStream()));
   
   location=reader.readLine();//서버로부터 reader에 위치정보를 받아  location에저장
   
   System.out.println("받은 위치정보"+location);//console화면 출력
   
  }catch(IOException ioe){
   System.err.println("Exception");
  }finally{
   try{
    socket.close();
   }catch(Exception ignored){}
  }
 }
}