t;." + ArrIP[1] + "." + ArrIP[2] + "." + ArrIP[3];
Initialize(ServerIP);
AddToMain("Starting Listener thread...");
//开始新线程
t = new Thread(new ThreadStart(Listener)); //侦听线程
t.Start();
this.btnStart.Enabled = false;
this.btnJoin.Enabled = false;
}
private void Send_Click(object sender, System.EventArgs e)
{
//开始新线程
t2 = new Thread(new ThreadStart(Send)); //侦听线程
t2.Start();
}
/// <summary>
///
/// </summary>
public void Send()
{
Thread.Sleep(1000);
Byte [] buffer = null;
System.Text.Encoding ASCII = System.Text.Encoding.ASCII;
String s = this.txtMsgSend.Text ;
if( s.Length == 0 )
return ;
if(String.Compare(s,0,"@",0,1,true,CultureInfo.InvariantCulture) == 0)
{
m_Done = true;
s = m_szHostName + ":@";
Application.Exit();
}
else
{
s = m_szHostName + ":" + s;
}
buffer = new Byte[s.Length + 1];
int len = ASCII.GetBytes( s.ToCharArray(), 0, s.Length, buffer, 0);
int ecode = m_Client.Send(buffer, len, m_RemoteEP);
if(ecode <= 0)
{
AddToMain("Error in send : " + ecode);
}
t2.Abort();
}
public static void Terminate()
{
m_Client.DropMulticastGroup(m_GroupAddress);
}
/// <summary>
/// 初始化
/// </summary>
public void Initialize(string IP)
{
m_Client = new UdpClient(LocalPort);
//设置广播组的网络地址
m_GroupAddress = IPAddress.Parse(IP);
try
{ //加入广播组
m_Client.JoinMulticastGroup(m_GroupAddress, 100);
}
catch(Exception ex)
{
string mm = ex.Message ;
AddToMain("Unable to join multicast group" + ex.Message);
}
//设置网络端点
m_RemoteEP = new IPEndPoint( m_GroupAddress, RemotePort );
}
/// <summary>
///
/// </summary>
public void Listener()
{
Thread.Sleep(2000);
System.Text.En
Initialize(ServerIP);
AddToMain("Starting Listener thread...");
//开始新线程
t = new Thread(new ThreadStart(Listener)); //侦听线程
t.Start();
this.btnStart.Enabled = false;
this.btnJoin.Enabled = false;
}
private void Send_Click(object sender, System.EventArgs e)
{
//开始新线程
t2 = new Thread(new ThreadStart(Send)); //侦听线程
t2.Start();
}
/// <summary>
///
/// </summary>
public void Send()
{
Thread.Sleep(1000);
Byte [] buffer = null;
System.Text.Encoding ASCII = System.Text.Encoding.ASCII;
String s = this.txtMsgSend.Text ;
if( s.Length == 0 )
return ;
if(String.Compare(s,0,"@",0,1,true,CultureInfo.InvariantCulture) == 0)
{
m_Done = true;
s = m_szHostName + ":@";
Application.Exit();
}
else
{
s = m_szHostName + ":" + s;
}
buffer = new Byte[s.Length + 1];
int len = ASCII.GetBytes( s.ToCharArray(), 0, s.Length, buffer, 0);
int ecode = m_Client.Send(buffer, len, m_RemoteEP);
if(ecode <= 0)
{
AddToMain("Error in send : " + ecode);
}
t2.Abort();
}
public static void Terminate()
{
m_Client.DropMulticastGroup(m_GroupAddress);
}
/// <summary>
/// 初始化
/// </summary>
public void Initialize(string IP)
{
m_Client = new UdpClient(LocalPort);
//设置广播组的网络地址
m_GroupAddress = IPAddress.Parse(IP);
try
{ //加入广播组
m_Client.JoinMulticastGroup(m_GroupAddress, 100);
}
catch(Exception ex)
{
string mm = ex.Message ;
AddToMain("Unable to join multicast group" + ex.Message);
}
//设置网络端点
m_RemoteEP = new IPEndPoint( m_GroupAddress, RemotePort );
}
/// <summary>
///
/// </summary>
public void Listener()
{
Thread.Sleep(2000);
System.Text.En
| 对此文章发表了评论 |

