• java 套接字


    简介

    RT

    code

    package com.kuang;
    
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    /**
     * Created by lee on 2021/4/1.
     */
    public class TcpServer {
        public static void main(String[] args) throws IOException {
            ServerSocket serverSocket = new ServerSocket(9999);
            Socket socket =serverSocket.accept();
            InputStream is = socket.getInputStream();
            byte[] buffer = new byte[1024];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int len;
            while((len=is.read(buffer)) != -1) {
                baos.write(buffer, 0, len);
            }
            System.out.println(baos.toString());
            baos.close();
            is.close();
            socket.close();
            serverSocket.close();
        }
    }
    
    
    package com.kuang;
    
    import java.io.IOException;
    import java.io.OutputStream;
    import java.net.InetAddress;
    import java.net.Socket;
    
    /**
     * Created by lee on 2021/4/1.
     */
    public class TcpClient {
        public static void main(String[] args) throws IOException {
            InetAddress serverIP = InetAddress.getByName("127.0.0.1");
            int port = 9999;
            Socket socket = new Socket(serverIP, port);
            OutputStream os = socket.getOutputStream();
            os.write("adfdsafdsafda".getBytes());
            os.close();
            socket.close();
        }
    }
    
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    Spark Streaming 的容错
    Master 接受其它组件的注册
    Spark Context 概述
    Python 使用random模块生成随机数
    Python 中print 和return 的区别
    Python 访问字典(dictionary)中元素
    PIL:处理图像的好模块
    2.线性回归
    3.梯度下降法
    4.pca与梯度上升法
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/14605818.html
Copyright © 2020-2023  润新知