Skip to content

Instantly share code, notes, and snippets.

@junbaor
Created October 24, 2016 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junbaor/c7b35c9a19b00cdfdde86a31cb6b0dff to your computer and use it in GitHub Desktop.
Save junbaor/c7b35c9a19b00cdfdde86a31cb6b0dff to your computer and use it in GitHub Desktop.
telnet
package com.junbaor.test;
import org.apache.commons.io.IOUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
/**
* Created by junbaor on 2016/10/19.
*/
public class TestServerSockt {
public static void main(String[] args) {
try {
final ServerSocket serverSocket = new ServerSocket(1088);
while (true) {
final Socket accept = serverSocket.accept();
new Thread(new Runnable() {
public void run() {
BufferedReader input = null;
PrintWriter output = null;
try {
input = new BufferedReader(new InputStreamReader(accept.getInputStream()));
output = new PrintWriter(accept.getOutputStream(), true);
output.println("Hello ...");
output.println();
while (true) {
try {
String inputStr = input.readLine();
System.out.println(">> " + inputStr);
output.println("飞不快的鸟不落在跑不快的牛的背上");
output.println();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("finally");
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}
}).start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment