Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Activity;
- import android.os.Bundle;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import android.util.Log;
- public class ClientInfoMain extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- try {
- ServerSocket ssocket = new ServerSocket(22266);
- Log.v("Tag", "port:" + ssocket.getLocalPort());
- Log.v("Tag", "" + "start");
- Socket socket = ssocket.accept();
- Log.v("Tag", "Accepted connection from " + socket.getRemoteSocketAddress());
- InputStream in = socket.getInputStream();
- OutputStream out = socket.getOutputStream();
- String str = null;
- int chr;
- while((chr = in.read()) != -1 ) {
- str += (char)chr;
- if ( str.indexOf("\r\n\r\n") > -1) {
- Log.v("Tag", "Found end of request");
- break;
- }
- }
- Log.v("Tag", "got string:" + str);
- String output = "HTTP/1.0 200 OK\r\n"
- + "Date: Tue Oct 05 16:19:04 GMT 2010\r\n"
- + "Server: JibbleWebServer/1.0\r\n"
- + "Content-Type: text/html\r\n"
- + "Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
- + "Content-Length: 6\r\n"
- + "Last-modified: Tue Oct 05 16:19:04 GMT 2010\r\n" +
- "\r\nHello!";
- out.write(output.getBytes());
- out.flush();
- in.close();
- out.close();
- } catch (IOException e) {
- Log.e("Tag", e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement