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

package com.cj;
//客户端

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

public class BasicSocketClient {
    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter pw = null;
        //创建Socket对象:两个参数1.服务端IP地址2.服务端所监听的端口
        try {
            socket = new Socket("192.168.43.57", 8888);
            pw = new PrintWriter(socket.getOutputStream());
            pw.println("服务端你好!!!");
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (pw != null) {
                pw.close();
            }
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
public class BasicSocketServer {
    public static void main(String[] args) {
        Socket socket=null;
        BufferedReader br=null;
        try {
            ServerSocket serverSocket=new ServerSocket(8888);
            System.out.println("服务器启动等待监听。。。。。");
            //开启监听
            socket=serverSocket.accept();
            //读取客服端发送的消息
            br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
            System.out.println(br.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (br!=null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

问题:服务端启动后,正常打印输出

客户端启动后,程序直接结束,不会输出“服务端你好”

image.png

image.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 17731楼
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 17732楼
Python 全系列/第一阶段:Python入门/编程基本概念 17734楼
Python 全系列/第一阶段:Python入门/编程基本概念 17736楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/JDBC技术 17737楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 17738楼
WEB前端全系列/第六阶段:音乐社区高级项目模块/音乐社区项目_蓝莓派 17739楼

为什么鼠标悬停在box上,图片2不往右移动

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实操二:定位练习3</title>
    <style>
        p{
            margin:0;
            padding:0;
        }
        a{
            text-decoration:none;
        }
        .box{
            width:290px;
            height:390px;
            text-align:center;
            position:relative;
        }
        img{
            width:120px;
            height:240px;
            position:absolute;
            left:85px;
            top:15px;
        }
        .box:hover>.img1{
            left:40px;
        }
        /* 为什么鼠标悬停在box上,图片2不移动? */
        .box:hover>.img2{
            left:130px;
        }
        .title{
            color:#333;
            margin-bottom:2px;
        }
        .desc{
            color:#999;
            font-size:14px;
       }
       .price{
            color:#c00;
            font-size:22px;
        }
        span{
        color:#c00;
        font-size:14px;
        margin-bottom:3px;
        }
        .text{
            width:290px;
            height:80px;
            position:absolute;
            bottom:30px;
            left:0;
        }

    </style>
</head>
<body>
    <div class="box">
        <img src="引用图片/img9.jpeg" alt="" class="img1">
        <img src="引用图片/img10.jpeg" alt="" calss="img2">
        <a href="#">
            <div class="text">
                <p class=title>金立S11</p>
                <p class="desc">超高清屏 超高性价比</p>
                <p class="price"><span>¥</span>2299</p>
            </div>
        </a>
    </div>
</body>
</html>


WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS常用属性 17741楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 17744楼
Python 全系列/第十二阶段:Python_Django3框架/Django进阶 17745楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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