zoukankan      html  css  js  c++  java
  • java tcp的理解

    java网络编程的理解
    tcp
    server端

    import java.io.DataInputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class testtcpserver {
     public static void main(String[] args) throws Exception {
      // TODO Auto-generated method stub
      ServerSocket ss = new ServerSocket(6666);//
      while(true) {
      Socket s = ss.accept();//接受
      System.out.println("a client connect");
      DataInputStream dis = new DataInputStream(s.getInputStream());
      System.out.println(dis.readUTF());
      dis.close();
      s.close();
      }
     }
    
    }
    



    client端

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.OutputStream;
    import java.net.Socket;
    public class tcpclient {
     public static void main(String[] args) throws Exception{
      Socket s = new Socket("192.168.1.90",6666);//申请
      OutputStream os = s.getOutputStream();
      DataOutputStream dos = new DataOutputStream(os);
      Thread.sleep(5000);
      dos.writeUTF("helle server");
      dos.flush();
      dos.close();
      s.close();
     }
    }
    


     

  • 相关阅读:
    docker-compose
    Cassandra
    npm常用命令
    k8s linux win10
    wsl2 docker 迁移
    docker http 代理
    mysql查看当前所有的数据库和索引大小
    mybatis 遍历list拼接 or查询
    es head crud
    nginx 代理转发mysql
  • 原文地址:https://www.cnblogs.com/zhujianxipan/p/3146905.html
Copyright © 2011-2022 走看看