
- 
public class sent {
public static void main(String[] args) throws IOException {
Socket sc= new Socket("127.0.0.1",10086);
OutputStream os = sc.getOutputStream();
os.write("aaa".getBytes());
os.close();
sc.close();
}
}
public class receive {
public static void main(String[] args) throws IOException {
ServerSocket sc= new ServerSocket(10086);
Socket accept = sc.accept();
InputStream is = accept.getInputStream();
int b;
while((b = is.read()) != -1){
System.out.println((char)b);
}
is.close();
sc.close();
}
}
这是一个简单的Java程序示例,展示了如何使用Socket进行客户端和服务器之间的通信。客户端向服务器发送aaa,服务器接收并打印接收到的数据。
1736

被折叠的 条评论
为什么被折叠?



