RFID conference sign-in system summary (21)-server-side Communication

Source: Internet
Author: User

 

There is nothing to talk about in this article. I just want to mention something different from the client.

The biggest difference between a server and a client is that it does not face a single connection, but some connections. For receiving and sending, it is specific Accept So there is Socketstateobject Parameters are always passed through. This parameter is mainly placed on the corresponding client Socket Connection and some status variables, in Accept This object is created after a connection is entered.

Public VoidListen (IntPort)

{

Ipendpoint IPE =NewIpendpoint (IPaddress. Any, Port );

Worksock =NewSocket (IPE. addressfamily, sockettype. Stream, protocoltype. TCP );

Worksock. BIND (IPE );

Work sock. Listen (100 );

Acpt =NewThread (NewThreadstart (acceptthread ));

Acpt. isbackground =True;

Acpt. Start ();

}

 

Private VoidAcceptthread ()

{

While(True)

{

Socket asock = worksock. Accept ();

Socketstateobject state =NewSocketstateobject (asock );

If(Onconnect! =Null)

Onconnect (State, system. eventargs. Empty );

Threadpool. queueuserworkitem (NewWaitcallback (receivethreadentrypoint), State );

}

}

 

Like aboveOnconnectEvents andReceivethreadentrypointMethod will follow up with such a parameter.

 

managing connections is a complex and technical activity. Data receiving and sending of available connections (or even some reception and sending must be related), connection availability monitoring, and removal of invalid connections. All of these should be recorded as appropriate, in addition, you need to UI the interface triggers events, which are crucial, it is also the most tricky, which involves multi-threaded synchronization and thread blocking.

the best solution to this extremely complex problem is to design, implement, or take it with reference to existing mature solutions. However, I have not been involved in development in these areas before, and I cannot find anything that is ideal at the moment. In addition, the project itself does not have high communication requirements, 10 connections last day (if any customer needs to 10 sign-in terminals, that's absolutely god, so far the most. 5 terminals, generally, no more than 3 ), so in this development, I used some simple methods to manage client connections.

because this part has not been carefully designed, it is temporarily unable to make a serious design, and the final implementation is not satisfactory to you, here we will not describe how to manage connections.

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.