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();

}

}


}

}



블로그 이미지

왕왕왕왕

,