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

public class BasicSocketClient {
    public static void main(String[] args) throws UnknownHostException {
        Socket socket=null;
        PrintWriter pw=null;
        //创建 Socket两个参数  1.服务端的IP地址 2.服务端所监听的端口
        try {
            socket=new Socket("127.0.0.1",8888);
            pw=new PrintWriter(socket.getOutputStream());
            pw.println("服务端 你好");
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (pw!=null){
                    pw.close();
                }
                if (socket!=null){
                    socket.close();
                }
            }catch (Exception 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()));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (br!=null){
                    br.close();
                }
                if (socket!=null){
                    socket.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }
}

老师为什么我两个代码运行完 客户端没有反应呢 没有输出那行话

JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 13276楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 13277楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 13278楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 13279楼
WEB前端全系列/第五阶段:前后端交互/网络请求AJAX 13280楼
Python 全系列/第四阶段:函数式编程和核心特性/函数式编程核心(高阶函数、闭包等) 13281楼

// pages/selectCity/selectCity.js
var request=require('../../utils/request.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        hotCityArr:[],
        latitude:"",
        longitude:"",
        demo:'11'


    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
          request('get','/api/hot/city',{},false,(res)=>{
              console.log(res);
              this.setData({
                  hotCityArr:res.data
              })
              console.log(this.data.hotCityArr);
          },(error)=>{
              console.log(error);
          },function(){})
    },
//    点击定位按钮,获取城市//需要在app.json permisson接口中配置权限
getLocation:res=>{
wx.getLocation({
  altitude: true,
  isHighAccuracy:true,
  highAccuracyExpireTime:4000,
  success:res=>{
  console.log(res.latitude);
  console.log(res.longitude);
  this.setData({
    latitude:res.latitude,
    longitude:res.longitude

  })
  console.log(this.data.demo);
 
  },
  fail:err=>{
      console.log(err);
  }
})
},

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})

老师 经纬度可以打印后台出来,但是为啥改data 就报错

image.png

WEB前端全系列/第十三阶段:微信小程序-安心食疗(旧)/安心食疗-定位-搜索 13283楼
大数据全系列/第十三阶段:Elasticsearch 分布式搜索/ElasticSearch 分布式搜索(旧) 13284楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 13290楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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