• java socket测试


    java  socket测试

    package com.vfsd.core;
    
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    public class VFSDClientServer {
        
        public static void main(String[] args) {
            //String hex = Integer.toHexString(var);
            
            String addressIP="115.26.69.66";
            int addressPort=8779;
            
            startServerSocket(addressIP,addressPort);
        }
    
        public static void startServerSocket(String addressIP,int addressPort) {
            try {
                //serverSocket = new ServerSocket(addressPort);
                Socket acceptSocket = new Socket(addressIP,addressPort);
                
                DataInputStream dis = new DataInputStream(acceptSocket.getInputStream());
                DataOutputStream dos = new DataOutputStream(acceptSocket.getOutputStream());
                
                while(true) {
                    //boolean isClosed = isServerClose(acceptSocket);//判断是否断开
                    
                    boolean isClosed = acceptSocket.isClosed();
                    if(true) {
                        //InetAddress spcketAddress = acceptSocket.getInetAddress();
                        //String hostName = spcketAddress.getHostAddress();
                        //String receiveMsg = dis.readUTF();
                        
                        //System.out.println("host name:"+hostName+"  msg:"+receiveMsg);
                        
                        sendData(dos);
                    }
                    
                }
                
                
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            
            
        }
        
        public static void sendData(DataOutputStream dos) {
            String dataStr = createRandomData3();
            try {
                System.out.println("=========================================");
                System.out.println(dataStr);
                
                dos.writeUTF(dataStr);
                //dos.write(dataStr.getBytes());
                //dos.writeBytes(dataStr);
                
                //byte[] bytes1 = new byte[dataStr.length()];
                /*for(int i=0;i<dataStr.length();i++) {
                    //bytes1[i] = dataStr.ge
                }*/
                //dos.writeBytes(dataStr);
                dos.flush();
                
                //byte[] bytes = new byte[2400];
                //dos.write(dataStr.getBytes());
                //dos.flush();
                
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
        
        public static String createRandomData3() {
            //int x_len = (int) (Math.random()*60+10);
            //int y_len = (int) (Math.random()*60+10);
            
            int x_len = 60;
            int y_len = 20;
            
            
            java.text.DecimalFormat   df   =new   java.text.DecimalFormat("#.00");  
            
            //int z_len = x*y;
            String dataStr="abcd";
            
            for(int x=0;x<x_len;x++) {
                for(int y=0;y<y_len;y++) {
                    double zd = Math.random()*10;
                    String zStr = df.format(zd);
                    double zd2 = Double.parseDouble(zStr);
                    int z = (int) (zd2*100);
                    //dataStr=dataStr+x+" "+y+" "+z+"
    ";
                    dataStr=dataStr+Integer.toHexString(z)+"";
                }
            }
            
            //System.out.println(dataStr);
            return dataStr;
        }
        
    }
  • 相关阅读:
    React Native ios打包
    ReactNative state更新,视图不更新的问题
    XF警告试图
    XF 彩色矩形块
    XF 定制图片
    XF 通过判断平台加载不同的图片
    XF 进度条和指示器
    XF 滑块和步进控件
    XF 开关控件
    XF 按钮控件
  • 原文地址:https://www.cnblogs.com/herd/p/13782117.html
Copyright © 2020-2023  润新知