Package ua

Source Code of ua.SimpleServer

package ua;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class SimpleServer {

  /**
   * @param args
   *            No parameters.
   */
  public static void main(String[] args) {

    ServerSocket serverSocket;
    try {
      serverSocket = new ServerSocket(23);
      while (true) {
        Socket socket = null;
        try {
          socket = serverSocket.accept();
          DataInputStream in = new DataInputStream(
              socket.getInputStream());
          String line = in.readUTF();
          System.out.println(line);
          DataOutputStream os = new DataOutputStream(
              socket.getOutputStream());
          os.writeChar(line.charAt(0));
          os.flush();
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          socket.close();
        }
      }
    } catch (IOException e1) {
      e1.printStackTrace();
    }
  }
}
TOP

Related Classes of ua.SimpleServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.