Logging Server based on SocketServer : Server « Network Protocol « Java






Logging Server based on SocketServer

  

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Main {

  public static void main(String args[]) throws Exception {
    ServerSocket serverSocket = new ServerSocket(8080);
    Socket socket = serverSocket.accept();

    InputStream inStream = socket.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
    String str = null;
    while ((str = reader.readLine()) != null) {
      System.out.println(str);
    }
  }
}

   
    
  








Related examples in the same category

1.A generic framework for a flexible, multi-threaded server
2.Server allows connections on socket 6123Server allows connections on socket 6123
3.This server displays messages to a single clientThis server displays messages to a single client
4.The client can specify information to control the output of a serverThe client can specify information to control the output of a server
5.A server can use specialized streams to deliver typed dataA server can use specialized streams to deliver typed data
6.Serve entire objects using ObjectOutputStreamServe entire objects using ObjectOutputStream
7.A multithreaded serverA multithreaded server
8.Base class to build multithreaded servers easily
9.Manage a pool of threads for clients
10.Client estimates the speed of the network connection to the server
11.This server retrieves the time using the RFC867 protocol.This server retrieves the time using the RFC867 protocol.
12.Quote Server
13.Client and Server Demo
14.Reflector
15.Simple Http Server