会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132493个问题

为什么我点击换页这个下拉菜单就会自动闭合

import React, { Component } from 'react'
import { Modal, Form, Input, Select, Radio, Dropdown, Space,Pagination } from 'antd'
import { icons } from '../../../components'



export default class ModleForm extends Component {
    constructor(props){
        super(props);
        this.state={
            currentIcons:icons.slice(0,10)
        }
    }
    formRef = React.createRef();
    onCancel = () => {
        this.props.dispatch({
            type: "hideModleForm"
        })
    }

    onSave = (values) => {
        console.log(values);
    }
    layout = {
        labelCol: { span: 4 },
        wrapperCol: { span: 20 }
    }
    render() {
        return (
            <Modal visible width={600} title={this.props.title}
                onCancel={this.onCancel}
                onOk={() => this.formRef.current.submit()}
            >
                <Form {...this.layout} ref={this.formRef} onFinish={this.onSave}>
                    <Form.Item label="父菜单">
                        {"无"}
                    </Form.Item>
                    <Form.Item label="菜单名称" name="name" rules={[{ required: true }]}>
                        <Input></Input>
                    </Form.Item>
                    <Form.Item label="访问路径" name="linkUrl" rules={[{ required: true }]}>
                        <Input></Input>
                    </Form.Item>
                    <Form.Item label="打开方式" name="openType" rules={[{ required: true }]}>
                        <Select>
                            <Select.Option value="1">当前窗口</Select.Option>
                            <Select.Option value="2">新窗口</Select.Option>
                        </Select>
                    </Form.Item>
                    <Form.Item label="图标" name="icon" rules={[{ required: true }]}>
                        <Dropdown trigger={['click']}
                            overlayStyle={{background:"#fff",padding:10}}
                            overlay={
                                <>
                                    <Radio.Group>
                                        <Space direction='vertical'>
                                            {this.state.currentIcons.map((ele, index) => {
                                                return (<Radio value={ele.name} >
                                                    {React.createElement(ele.renderFn)}
                                                    <span style={{ margin: 5 }} key={index}>{ele.name}</span>
                                                </Radio>)
                                            })}
                                        </Space>
                                    </Radio.Group>
                                    <div style={{textAlign:"right",padding:10}}>
                                        <Pagination showSizeChanger={false} 
                                        size="small" 
                                        total={icons.length}
                                        onChange={(page,pageSize)=>{
                                            this.setState({
                                                currentIcons:icons.slice(pageSize*(page-1),pageSize*page)
                                            })
                                        }}
                                        ></Pagination>
                                    </div>
                                </>
                            }>
                            <Input></Input>
                        </Dropdown>
                    </Form.Item>
                    <Form.Item label="权限" name="isOfAdmin" rules={[{ required: true }]}>
                        <Radio.Group>
                            <Radio value="1">仅超管可见</Radio>
                            <Radio value="2">不限</Radio>
                        </Radio.Group>
                    </Form.Item>
                    <Form.Item label="菜单名称" name="name" rules={[{ required: true }]}>
                        <Input></Input>
                    </Form.Item>
                </Form>
            </Modal>
        )
    }
}


WEB前端全系列/第十六阶段:React企业级项目/企业级后台管理系统 28966楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 28967楼
JAVA 全系列/第一阶段:JAVA 快速入门/控制语句、方法、递归算法 28968楼
JAVA 全系列/第四阶段:网页编程和设计/CSS3(旧) 28969楼
JAVA 全系列/第八阶段:Linux入门到实战/Git 28972楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 28974楼

老师好,以下是我的代码和实现的效果:

package com.lichen.client;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Test {
    public static void main(String[] args) throws IOException {
        System.out.println("----------客户端已启动--------------");
        //1.创建Socket对象
        Socket client = new Socket("localhost", 9999);
        //2.创建输出流
        OutputStream os = client.getOutputStream();
        os.write("Do you copy?".getBytes());
        //3.获取输入流
        InputStream is = client.getInputStream();
        //中转站
        byte[] buf = new byte[1024];
        int len = 0;
        while((len = is.read(buf)) != -1) {
            System.out.println(new String(buf, 0, len));
        }
        //4.关闭流

        if (is != null) {
            is.close();
        }
        if (os != null) {
            os.close();
        }
        if (client != null) {
            client.close();
        }
        System.out.println("----------客户端已关闭--------------");
    }
}
package com.lichen.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Test {
    public static void main(String[] args) throws IOException {
        System.out.println("----------服务端已启动--------------");
        //1.创建ServerSocket对象
        ServerSocket sever = new ServerSocket(9999);
        //2.监听是否有客户端来请求链接
        Socket client = sever.accept();
        //3.获取输入流
        InputStream is = client.getInputStream();
        //中转站
        byte[] buf = new byte[1024];
        int len = 0;
        while((len = is.read(buf)) != -1) {
            System.out.println(new String(buf, 0, len));
            if(len < buf.length) {
                break;
            }
        }
        //4.创建输出流
        //"copy that."
        OutputStream os = client.getOutputStream();
        os.write("Copy that.".getBytes());
        //5.关闭流,关闭Socket
        if(os != null) {
            os.close();
        }
        if(is != null) {
            is.close();
        }
        if(client != null) {
            client.close();
        }
        System.out.println("----------服务端已关闭--------------");
    }
}

我的问题是:为什么服务端在读客户端发来的数据时,要加

            if(len < buf.length) {
                break;
            }

这段代码,而客户端在读服务端的时候就不需要呢?

JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 28979楼
Python 全系列/第二阶段:Python 深入与提高/模块 28980楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637