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

普通字符串UTF

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

651
使用DataOutputStream的纯字符串UTF-8通信

/**来自 
 NowJava.com - 时  代  Java**/


import org.apache.logging.log4j.LogManager;

import org.apache.logging.log4j.Logger;


import java.io.DataOutputStream;

import java.io.IOException;

import java.io.OutputStreamWriter;

import java.net.Socket;

import java.security.NoSuchAlgorithmException;

import java.security.NoSuchProviderException;


public class Client {

    private static final Logger logger = LogManager.getLogger(Client.class);

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

        if (args.length != 2) {

            System.err.println("Usage: java Client <host name> <port number>");

            System.exit(1);/** 来自 N o w J a v a . c o m**/

        }


        String hostName = args[0];

        String str = "Hello World!";

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


        // Communication

        try{

            // Sockets

            Socket socket = new Socket(hostName, portNumber);

            
展开阅读全文