日期:2014-05-18 浏览次数:21156 次
public void Send(string content, string format)
{
UdpClient client = new UdpClient();
client.Connect(_ip, _port);
client.DontFragment = true;
byte[][] ndata = null;
byte[] btformat = Encoding.GetEncoding("gb2312").GetBytes(format);
byte[] data = Encoding.GetEncoding("gb2312").GetBytes(content);
byte[] sign = Encoding.GetEncoding("gb2312").GetBytes("!part");
#region 如果数据报大于1000字节,则分段
if (data.Length > 1000)
{
int pNo = data.Length % 1000 == 0 ? data.Length / 1000 : data.Length / 1000 + 1;
ndata = new byte[pNo][];
for (int i = 0; i < pNo; i++)
{
byte[] temBytes = new byte[1000];
if (i == pNo - 1)
temBytes = new byte[data.Length % 1000];
int add = 0;
for (int j = i * 1000; j < (i + 1) * 1000; j++)
{
try
{
temBytes[add] = data[j];
add++;
}
catch
{
goto Add;
}
}
goto Add;
Add:
ndata[i] = temBytes;
//btformat.CopyTo(ndata[i], 0);
ndata[i] = CopyTo(btformat, ndata[i]);
byte[] te = ndata[i];
if (i != (pNo - 1)) <