美文网首页
ClientDemo

ClientDemo

作者: 醉酒青牛_fa4e | 来源:发表于2018-03-26 23:56 被阅读0次

using UnityEngine;
using System.Collections;
using System.Text;
using System;
/// <summary>
/// 客户端实现
/// </summary>
public class ClientDemo : MonoBehaviour
{
//待解析地址
public string wwwAddress = "";

void Start ()
{
    //消息处理
    NetUtility.Instance.SetDelegate ((string msg) => {
        Debug.Log (msg + "\r\n");
    });
    //连接服务器
    NetUtility.Instance.ClientConnnect ();
    //开启协程

// StartCoroutine (ServerStart ());
}

void OnGUI()
{
    GUILayout.Label ("Address");
    wwwAddress = GUILayout.TextField (wwwAddress);
    if (GUILayout.Button ("Send")) {
        //开启协程
        StartCoroutine (ServerStart ());
    }
}

IEnumerator ServerStart ()
{
    //加载网页数据
    WWW www = new WWW (wwwAddress);
    yield return www;
    //编码获取内容
    string content = UTF8Encoding.UTF8.GetString (www.bytes);
    //内容测试
    Debug.Log (content);
    //待发送对象
    NetModel nm = new NetModel ();
    //消息体
    nm.senderIp = "127.0.0.1";
    nm.content = content;
    nm.time = DateTime.Now.ToString ();
    //发送数据对象
    NetUtility.Instance.SendMsg (nm);
}

}

相关文章

网友评论

      本文标题:ClientDemo

      本文链接:https://www.haomeiwen.com/subject/ongdcftx.html