客户端:delegate void AIQIYI(string str);
private byte[] data = { };
public frmClient()
{
InitializeComponent();
TextBox.CheckForIllegalCrossThreadCalls = false;
}
Thread threadClient = null; // 创建用于接收服务端消息的 线程;
Socket sockClient = null;
private void btnConnect_Click(object sender, EventArgs e)
{
IPAddress ip = IPAddress.Parse(txtIp.Text.Trim());
IPEndPoint endPoint=new IPEndPoint (ip,int.Parse(txtPort.Text.Trim()));
sockClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
ShowMsg("与服务器连接中……");
sockClient.Connect(endPoint);
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
return;
//this.Close();
}
ShowMsg("与服务器连接成功!!!");
threadClient = new Thread(RecMsg);
threadClient.IsBackground = true;
threadClient.Start();
}
评论