69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
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 SocketsUDP
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
textBox2.Text="";
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
textBox2.Text = textBox2.Text + CClientUDP.ByteData[i];
|
|
}
|
|
|
|
button1_Click(sender, e);
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
char[] cc = new char[1] {' '};
|
|
string[] sp;
|
|
byte[] sd = new byte[8];// { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80 };
|
|
sp =textBox1.Text.Split(cc);
|
|
for (int i = 0; i <= sd.GetUpperBound(0); i++)
|
|
{
|
|
sd[i] =Convert.ToByte( sp[i]);
|
|
}
|
|
CClientUDP.SendUdp(sd);
|
|
|
|
CClientUDP.ReceiveUdp(tbLocalIp.Text, Convert.ToInt32(tbLocalPort.Text));
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
EndPoint rServer = (EndPoint)new IPEndPoint(IPAddress.Parse(tbRemoteIp.Text), Convert.ToInt32(tbRemotePort.Text));
|
|
EndPoint lServer=(EndPoint)new IPEndPoint(IPAddress.Parse(this.tbLocalIp.Text), Convert.ToInt32(this.tbLocalPort.Text));
|
|
CClientUDP.InitClientUDP(lServer, rServer);
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
CClientUDP.CloseUDP();
|
|
|
|
timer1.Enabled = false;
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
timer1.Enabled = true;
|
|
}
|
|
}
|
|
} |