SHARE
TWEET

Untitled

a guest Jun 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import java.io.*;
  5. import java.net.*;
  6. import java.util.*;
  7.  
  8. import android.util.Log;
  9.  
  10. public class ClientInfoMain extends Activity {
  11.     /** Called when the activity is first created. */
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.main);
  16.        
  17.         try {
  18.             ServerSocket ssocket = new ServerSocket(22266);
  19.             Log.v("Tag", "port:" + ssocket.getLocalPort());
  20.             Log.v("Tag", "" + "start");
  21.             Socket socket = ssocket.accept();
  22.             Log.v("Tag", "Accepted connection from " + socket.getRemoteSocketAddress());
  23.             InputStream in = socket.getInputStream();
  24.             OutputStream out = socket.getOutputStream();
  25.             String str = null;
  26.             int chr;
  27.             while((chr = in.read()) != -1 ) {
  28.                 str += (char)chr;
  29.                 if ( str.indexOf("\r\n\r\n") > -1) {
  30.                     Log.v("Tag", "Found end of request");
  31.                     break;
  32.                 }
  33.             }
  34.             Log.v("Tag", "got string:" + str);
  35.             String output = "HTTP/1.0 200 OK\r\n"
  36.                 + "Date: Tue Oct 05 16:19:04 GMT 2010\r\n"
  37.                 + "Server: JibbleWebServer/1.0\r\n"
  38.                 + "Content-Type: text/html\r\n"
  39.                 + "Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
  40.                 + "Content-Length: 6\r\n"
  41.                 + "Last-modified: Tue Oct 05 16:19:04 GMT 2010\r\n" +
  42.             "\r\nHello!";
  43.             out.write(output.getBytes());
  44.             out.flush();
  45.             in.close();
  46.             out.close();
  47.         } catch (IOException e) {
  48.                 Log.e("Tag", e.getMessage());
  49.         }        
  50.     }
  51. }
RAW Paste Data
Top