Socket TCP 异步-Client端
C# Socket TCP 异步-Client端
using System.Net.Sockets;
using System.Net;
namespace client
{
public partial class client : Form
{
byte[] bytes = new byte[1024];
Socket senderSock;
public client()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IPAddress ipAddr = IPAddress.Parse("192.168.0.4");
senderSock = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
StateObject so = new StateObject();
so.socket = senderSock;
senderSock.BeginConnect(ipAddr, 9510, new AsyncCallback(Connect), so);
}
delegate void MyDelegate(string s);
void setextBox1(string s)
{
textBox1.Text += (s + "\n");
}
public void Connect(IAsyncResult ar)