/*Received*/
Byte[] bytesReceived = new Byte[256];
int bytes = 0;
string page = "Server: Success Connect " + server + ":
";
do
{
bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
}
while (bytes > 0);
Test.text = page;
}
catch (Exception e)
{
print(e);
}
}
} 服务器打开的话客户端收到返回信息(和发送一样)运行效果如下图:2. 下载和本地保存实例 下载是羽化一直关心的问题,由于开发的是网页和手机平台,有些资源要得到用户许可下载到本地,这样可以加速游戏运行,所以这里羽化就以一张图片为例,这里做了平台判断,在Android上依然可以保存在SD上,PC端就下载到了工程的download里面。代码如下:Download.cs[csharp] view plaincopyprint?
using UnityEngine;
using System.Collections;
using System.IO;
public class Download : MonoBehaviour
{
public string url = "http://ww3.sinaimg.cn/large/80dfe250jw1dle1r2v4t9j.jpg";
public GUIText Test;
WWW www;
Color Alpha;
bool Appear = false;
int a = 0;