title: Socket Server/Client with two Android devices
body: <p>So I have a tablet and I want to basically make it a TCP (or UDP) Socket Server so multiple phones can send data to it. I also want to be able to send responses back to the phones. What I have so far isn't working...</p>
  
  <p>Server:</p>
  
  <pre><code>Log.i("Server", "Starting server...");
                  try {
                      ServerSocket ss = new ServerSocket(8080);
                      Log.i("Server", "Server status: " + ss.isBound());
                      while(true){
                          //Server is waiting for client here, if needed
                          Socket s = ss.accept();
                          Log.i("Server", "Server is accepting connections: " + s.isConnected());
                          BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
                          PrintWriter output = new PrintWriter(s.getOutputStream(),true); //Autoflush
                          Log.i("Server", "Initialized input and output");
                          String st = input.readLine();
                          Log.i("Server", "From client: "+st);
                          output.println("Good bye and thanks for all the fish :)");
                      }
  
                  } catch (UnknownHostException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  </code></pre>
  
  <p>And client (phone):</p>
  
  <pre><code>try {
                      Socket s = new Socket("192.168.0.106", 8080);
  
                      //outgoing stream redirect to socket
                      OutputStream out = s.getOutputStream();
  
                      PrintWriter output = new PrintWriter(out);
                      output.println("Hello Android!");
                      BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
                      //read line(s)
                      String st = input.readLine();
                      tv.setText(st);
                      //Close connection
                      s.close();
  
  
                  } catch (UnknownHostException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  </code></pre>