udp

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;


namespace WindowsApplication26
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dicIpName.Add("大家","大家");
}
Dictionary<string,string> dicIpName = new Dictionary<string,string>();

private void button1_Click(object sender, EventArgs e)
{
byte[] bytes = ComposeData("0", myIp, "雷盼", "127.0.0.1", "###大家好###");
ParseData(bytes);
}
string myIp = "10.144.93.187";
private void ParseData(byte[] bytes)
{
string strTemp = System.Text.Encoding.Unicode.GetString(bytes);
string[] strArr = strTemp.Split(new char[] {'#'}, 5);
if (strArr[1].Equals(myIp))
return;
switch (strArr[0])
{
case "0":
dicIpName.Add(strArr[1],strArr[2]);
ListMemberFlush();
byte[] byteArr = ComposeData("0", myIp, "雷盼", myIp, "");
Send(byteArr);
break;
case "1":
break;
case "2":
break;
default:
break;
}
}

private void ListMemberFlush()
{

}

public byte[] ComposeData(string strType, string strFromIp, string strFromName, string strToIp, string strMsg)
{
string strResult = string.Format("{0}#{1}#{2}#{3}#{4}", strType, strFromIp, strFromName, strToIp, strMsg);
return System.Text.Encoding.Unicode.GetBytes(strResult);
}

private void Send(byte[] bytes)
{
}
}

 


}

posted @ 2012-07-20 00:28  雷盼  阅读(153)  评论(0编辑  收藏  举报