package com.heima.lianxi;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Lianxi6 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ServerSocket ss =new ServerSocket(54321);
System.out.println("服务器启动,绑定54321");
while (true){
final Socket socket= ss.accept();
new Thread(){
public void run(){
try {
BufferedReader br =new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintStream ps =new PrintStream(socket.getOutputStream());
System.out.println(new StringBuffer(br.readLine()).reverse().toString());
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
}
}
Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at com.heima.lianxi.Lianxi6.main(Lianxi6.java:17)
|
|