2016-09-10 4 views
1

私は、クライアントがボタンclick.Iでテキストをサーバーに送ることができるアプリケーションを作成していますが、クライアント側のボタンが押されるたびに何も起こりません。サーバーはクライアントのJavaからテキストを受け取ることができません

そして時々私はコンソールのこの行を得ました[email protected]。 これはなぜ起こっているのですか?

サーバコード:

public static ServerSocket server = null; 
public static Socket client = null; 

public static void main(String []arg)throws IOException{ 
    try { 
     server = new ServerSocket(8002); 
     System.out.println("Server Started..............."); 
     while(true){ 
     client = server.accept(); 
     DataInputStream in = new DataInputStream(client.getInputStream()); 
     String msg = in.readLine(); 
     System.out.println("and: "+msg); 
     } 
    }catch(IOException r){ 
     System.out.println("error :"+r.getMessage()); 
    } 
} 

クライアントコード:

public void send(){ 
    send.setOnClickListener(
      new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        Socket cs = null; 
        try { 
         cs = new Socket("192.168.1.100", 8002); 
         DataOutputStream out = new DataOutputStream(cs.getOutputStream()); 
         out.writeBytes(text.toString()); 
        } catch (IOException e) { 
         Toast.makeText(KeyboardActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); 
        } 
       } 
      } 
    ); 
} 

答えて

2

textEditTextだからです。

私はあなたが実際に意味を考える

、代わりの

out.writeBytes(text.getText().toString()); 

、いつものように

out.writeBytes(text.toString()); 
+0

うん、それは... !!!私はそのような騒ぎです:( –

-2

、あなたは行を読んでいるが、あなたは行を書いていません。送信されるメッセージにラインターミネータを追加します。

関連する問題