Android Open Source - dpsearch-android T C P Desktop Server






From Project

Back to project page dpsearch-android.

License

The source code is released under:

GNU General Public License

If you think the Android project dpsearch-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.dataparksearch;
/* w w w. j a  va2 s .c  o m*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPDesktopServer implements Runnable{
  
    public static final String SERVERIP = "inet-sochi.ru";
    public static final int SERVERPORT = 7003;
         
    public void run() {
         try {
           System.out.println("S: Connecting...");
              
             ServerSocket serverSocket = new ServerSocket(SERVERPORT);
             while (true) {
                
                Socket client = serverSocket.accept();
                System.out.println("S: Receiving...");

                try {
                      BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
                      String str = in.readLine();
                      System.out.println("S: Received: '" + str + "'");
                    } catch(Exception e) {
                        System.out.println("S: Error");
                        e.printStackTrace();
                    } finally {
                      client.close();
                        System.out.println("S: Done.");
                    }

             }
              
         } catch (Exception e) {
             System.out.println("S: Error");
             e.printStackTrace();
         }
    }
    
    public static void main (String a[]) {
      Thread desktopServerThread = new Thread(new TCPDesktopServer());
      desktopServerThread.start();
    }
}




Java Source Code List

com.dataparksearch.DPS_Activity.java
com.dataparksearch.TCPClient.java
com.dataparksearch.TCPDesktopServer.java