[java]代码库
package cn.itcast.sh.reg;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class RegServer {
public static void main(String[] args) throws IOException {
/*
* 使用tcp通信,创建服务端
*/
ServerSocket ss = new ServerSocket(9090);
//接受客户端
Socket s = ss.accept();
//获取输入流对象接受客户端提交过来的数据
InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = in.read(buf);
System.out.println(new String(buf,0,len));
//给客户端回送数据,告诉客户端注册成功
OutputStream out = s.getOutputStream();
out.write("<font color='red' size='7'>恭喜,注册成功</font>".getBytes());
//关闭客户端
s.close();
//关闭服务端
ss.close();
}
}