Created
October 24, 2016 06:41
-
-
Save junbaor/c7b35c9a19b00cdfdde86a31cb6b0dff to your computer and use it in GitHub Desktop.
telnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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