集册 Java实例教程 普通字符串UTF

普通字符串UTF

欢马劈雪     最近更新时间:2020-01-02 10:19:05

490
纯字符串UTF-8网络通信



import org.apache.logging.log4j.LogManager;

import org.apache.logging.log4j.Logger;/**来自 时代Java公众号**/


import javax.crypto.NoSuchPaddingException;

import java.io.*;

import java.net.ServerSocket;

import java.net.Socket;

import java.security.NoSuchAlgorithmException;

import java.security.NoSuchProviderException;


public class Server {

    private static final Logger logger = LogManager.getLogger(Server.class);//时代Java

    public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, IOException {

        if (args.length != 1) {

            System.err.println("Usage: java Server <port number>");

            System.exit(1);

        }

        int portNumber = Integer.parseInt(args[0]);

        logger.trace("Sever started");


        ServerSocket serverSocket;

        Socket clientSocket;

        DataInputStream in;


        try {

            serverSocket = new ServerSocket(portNumber);

            clientSocket = serverSocket.accept();


            in = 
展开阅读全文