java 客户端代码
创建socket
绑定
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
public class JavaClient {
public static void main(String [] args) throws InterruptedException, IOException
{
InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 5678); //创建socket
Socket sock = new Socket();
sock.connect(addr);//连接服务器
BufferedReader is = null;
PrintWriter os = null;
os = new PrintWriter(sock.getOutputStream()); //管道的写工具
is = new BufferedReader(new InputStreamReader(sock.getInputStream())); //管道的读工具
BufferedReader user = new BufferedReader(new InputStreamReader(System.in)); //从控制台读取命令的工具
System.out.print("client say:");
String msg = user.readLine();
while(!msg .equals("bye"))
{
os.println(msg);
os.flush();
String ec
java 客户端与c++服务器端tcp通信 demo
最新推荐文章于 2022-07-17 01:20:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)