I. There is a picture and the truth is simple.,
B,
Thread Constructor
(ParameterizedThreadStart)
Initializes a new instance of the Thread class and specifies the delegate that allows the object to be passed to the Thread when the Thread starts.
Parameters
Start
Type: System. Threading. ParameterizedThreadStart
ParameterizedThreadStart delegate, which indicates the method to be called when the thread starts execution.
C. Server threads and sockets
Thread:
Threadmain listen ()
Threadaccept accept ()
Threadconmmunication send () receive ()
Socket:
Socketlisten listen ()
Socketsend send ()
Socketreceive receive ()
Ii. client code:
Socket socketClient = = SetText( btn_login_Click(= IPAddress ip == = ThreadStart( threadClient = = ; () [] buffer = [ * * length = ReceiveMsg = System.Text.Encoding.UTF8.GetString(buffer,,length); ShowMsg( + ShowMsg( (= .Invoke(st, tb_infor.AppendText(str + GetCurrentTime() + btn_sendmessage_Click( txtMsg = [] buffer = + = =
Iii. server code:
= ; Thread threadWatch = ; SetText( btn_StartServer_Click( socketWatch = IPAddress ip = IPEndPoint endPoint = IPEndPoint(ip, socketWatch.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, socketWatch.Listen( ThreadStart threadDelegate = ThreadStart( threadWatch = threadWatch.IsBackground = ShowMsg( ( SetText d = .Invoke(d, tb_infor.AppendText(str + GetCurrentTime() + = ; () SocketConnection = ShowMsg( ParameterizedThreadStart pts = = = btn_sendany_Click( SendMsg = (SendMsg != [] buffer = System.Text.Encoding.UTF8.GetBytes(SendMsg); + = = ServerRecMsg(= socketClientPara ( [] arrServerRecMsg = [ * * length = strSRecMsg = Encoding.UTF8.GetString(arrServerRecMsg, ShowMsg( +