cocos-creator连接服务端 注册与登入

本文详细介绍了如何使用Cocos Creator与服务端进行通信,实现用户注册和登录的功能。通过HTTP请求或者WebSocket连接,发送JSON数据进行账号验证。涵盖了客户端与服务器的API设计、数据交互流程及错误处理策略。
摘要由CSDN通过智能技术生成

cc.Class({
    extends: cc.Component,

    properties: {
              //外部传入account输入款
            account:cc.EditBox,
             //外部传入password输入款
            password:cc.EditBox,
            tips:cc.Node,
            labyer:cc.Label,
    },

    onLoad () {},

    start () {
            this.ws=null;
            this.conect();
    },

    conect:function()
    {
       this.ws = new WebSocket("ws://192.168.0.118:8000/login");
        //写好的服务端,根据不同的返回值,输出对应的提示
       this.ws.onopen = function (event) {
            console.log("Send Text WS was opened.");
        }.bind(this);
        this.ws.onmessage = function (event) {
            switch(JSON.parse(event.data).cmd)
            {
                case 2:
                this.tips.active=true;
                this.labyer.string='注册失败'
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值