package javaServer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
class Server {
public static void main(String[] args) {
System.out.println("S: Connecting...");
try {
ServerSocket serverSocket = new ServerSocket(5555);
while (true) {
Socket client = serverSocket.accept();
Thread desktopServerThread = new Thread(new startThread(client));
desktopServerThread.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static class startThread implements Runnable {
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
public startThread(Socket client) {
// TODO Auto-generated constructor stub
this.socket = client;
}
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("from " + socket.getInetAddress() + ":" + socket.getPort());
OutputStream outputStream;
try {
outputStream = socket.getOutputStream();
PrintStream printStream = new PrintStream(outputStream);
printStream.print("Server Send data ~~ ");
printStream.close();
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
'안드로이드' 카테고리의 다른 글
안드로이드 이클립스환경 설치 (0) | 2015.10.05 |
---|---|
안드로이드 다중 서버클라이언트(xml부분) (0) | 2015.05.27 |
안드로이드 다중 서버 클라이언트(클라이언트부분) (0) | 2015.05.27 |
웹뷰 셋팅과 뒤로가기이벤트 (0) | 2015.05.15 |
탭호스트 사용법 (0) | 2015.05.15 |