[java]代码库
import java.io.*;
import java.net.*;
public class ServetSocket {
public static void main(String[] a){
try{
ServerSocket ss=new ServerSocket(8088);//定义服务接口
Socket s =ss.accept();//服务器的端口接受
DataOutputStream out = new DataOutputStream(s.getOutputStream());
out.writeUTF("你好!!!");
}catch(Exception e){
e.printStackTrace();
}
}
}
import java.io.*;
import java.net.Socket;
public class Client {
public static void main(String [] a){
try{
Socket s= new Socket("127.0.0.1",8088);
DataInputStream in = new DataInputStream(s.getInputStream());
String string = in.readUTF();
System.out.println("服务器说:"+string);
}catch(Exception e){
e.printStackTrace();
}
}
}