Winform Learning Log (22) ------ socket (tcp) send messages to each other

Source: Internet
Author: User

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( +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.