会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132435个问题
Python 全系列/第一阶段:Python入门/控制语句 4246楼

package cn.itbaizhan;
//客户端
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {

    public static void main(String[] args) throws IOException {
        Socket client=new Socket("192.168.0.103",888);
        OutputStream os=client.getOutputStream();
        InputStream is=client.getInputStream();
        os.write("aaa".getBytes());
        os.flush();
        int len=0;
        byte[] bt1=new byte[1024];
        while((len=is.read(bt1))!=-1){
            System.out.println(new String(bt1,0,len));
            if(len<bt1.length){//
                break;
            }
        }
        if(is!=null){
            is.close();
        }
        if(os!=null){
            os.close();
        }
        if(client!=null){
            client.close();
        }



    }

}
========
package cn.itbaizhan;
//服务器端
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=new ServerSocket(888);
        Socket client=serverSocket.accept();//监听
        InputStream is=client.getInputStream();
        byte[] bt2=new byte[1024];
        int len=0;
        while ((len=is.read(bt2))!=-1){
            System.out.println(new String(bt2,0,len));
        }
        OutputStream os=client.getOutputStream();
        os.write("bbb".getBytes());
        os.flush();
        if(os!=null){
            os.close();
        }
        if(is!=null){
            is.close();
        }
        if(client!=null){
            client.close();
        }
        if(serverSocket!=null){
            serverSocket.close();
        }

    }
}

blob.png

blob.png

老师,为什么我这里服务器端能读数据,客户端读不了呢

JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 4247楼
JAVA 全系列/第四阶段:网页编程和设计/JavaScript语言 4248楼

QQ截图20201113170207.png

QQ截图20201113170224.png

小米官网.rar

图一是别人的样子,图二是我的样子。我把字体图标放大,文字就下去了,和图标没法对齐。。。

WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS3新特性 4250楼
JAVA 全系列/第七阶段:生产环境部署与协同开发/Docker 4251楼

求老师帮忙看下我的代码哪里出错了,效果一直出不来。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas小球动画</title>
    <style>
        canvas{
            border:1px solid;
        }
    </style>
</head>
<body>
    <canvas width="400" height="300">你的浏览器不支持canvas标签</canvas>
    <script>
        var mycanvas=document.querySelector('canvas');
        var ctx=mycanvas.getContext('2d');
        var x=50;
        var y=50;
        var speed=-1;
        var speedY=2;
        //绘制一个小球
        var timer=setInterval(function(){
            ctx.clearRect(0,0,mycanvas.width,mycanvas.height);
            speed+=speed;
            if(x<=20){
                speed=Math.abs(speed);
            }else if(x>=380){
                speed=-speed;
            }
            speedY+=speedY;
            if(y>=280){
                speedY=-speedY;
            }else if(y<=20){
                speedY=-speedY;
            }
            ctx.beginPath();
            ctx.arc(x,y,20,0,2*Math.PI);
            // ctx.stroke();
            ctx.fillStyle='skyblue';
            ctx.fill();
            ctx.closePath();
        },60);
    </script>
</body>
</html>


WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 4252楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 4253楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器 4254楼
WEB前端全系列/第十一阶段:Nodejs编程模块--/Nodejs基础 4255楼

'''

load game window

'''


import pygame

# define constants

SCREEN_WIDTH=700

SCREEN_HEIGHT=500

BG_COLOR=pygame.Color(255,255,255)

#from curses import window

class MainGame():

    window=None

    # initialization method

    def __init__(self) -> None:

        pass

    # start game

    def startGame(self):

        #initialize the window

        pygame.display.init()

        #set the size of window

        MainGame.window=pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

        # set the title of window

        pygame.display.set_caption("tank war1.03")

        while True:

            # set the fill color for the window

            MainGame.window.fill(BG_COLOR)

            pygame.display.update


    # end game

    def endGame(self):

        pass


class Tank():

    def __init__(self) -> None:

        pass

    #defition of show tank

    def displayTank(self):

        pass


    #movement of tank

    def move(self):

        pass


    #shoot

    def shot(self):

        pass



#our tank

class MyTank(Tank):

    #initialization method

    def __init__(self) -> None:

        pass


#enemy tank

class EnemyTank(Tank):

    def __init__(self) -> None:

        pass


# class bullet

class Bullet():

    def __init__(self) -> None:

        pass


    #show bullet

    def displayBullet(self):

        pass


    #move

    def move(self):

        pass


# class wall

class Wall():

    def __init__(self) -> None:

        pass


    # the defition of show wall

    def displayWall(self):

        pass

# class explosion effect

class Explode():

    def __init__(self) -> None:

        pass


    #display the effect of explosion

    def displayExplode(self):

        pass



#class of sound effect

class Music():

    def __init__(self) -> None:

        pass


    #play music

    def playMusic(self):

        pass


# main method

if __name__ =='__main__':

    # call startGame() in the main class

    MainGame().startGame()



为什么我这窗口还是黑色的

image.png


Python 全系列/第二阶段:Python 深入与提高/(旧)坦克大战 4256楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 4257楼
Python 全系列/第一阶段:Python入门/控制语句 4259楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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