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='注册失败'
cocos-creator连接服务端 注册与登入
最新推荐文章于 2024-08-08 01:09:16 发布
本文详细介绍了如何使用Cocos Creator与服务端进行通信,实现用户注册和登录的功能。通过HTTP请求或者WebSocket连接,发送JSON数据进行账号验证。涵盖了客户端与服务器的API设计、数据交互流程及错误处理策略。
摘要由CSDN通过智能技术生成