Windows Phone uses beetle to implement TCP communication for object interaction

Source: Internet
Author: User
Tags elastic search
ArticleDirectory
    • Interface Creation
    • Detailed code implementation

Beetle provides the implementation of beetle. SL Based on Silverlight. Because WP7 Development also provides socket support, beetle. SL can be fully used in WP7. Protobuf.net also supports WP7. Therefore, you can use beetle. SL + protobuf.net to implement object-based TCP communication applications in WP7.

First create a WP project, reference beetle. WP. dll, beetle. WP. protobuf. dll and protobuf-net.DLL respectively; the above components can be divided into other.

Interface Creation

The main function is to query the customer information after logging in. You can enter the name of the customer to be queried.

Details Code Implementation

Create a protobuf-based TCP connection andProgramBinding related events during loading

Private beetle. protobufadapter. protobufchannel mchannel = new Beetle. protobufadapter. protobufchannel (); Private void phoneapplicationpage_loaded (Object sender, routedeventargs e) {messageadapter. loadmessage (GetType (). assembly); mchannel. connected + = onconnected; mchannel. disposed + = ondisposed; mchannel. receive + = onreceive; mchannel. error + = onerror ;}

The connection button event is used to establish a TCP connection. After the connection is successful, the query button becomes available.

Private void initialize connect_click (Object sender, routedeventargs e) {mchannel. connect (txtipaddress. text, 4520);} private void onconnected (Object sender, eventchannelarges e) {This. dispatcher. begininvoke () => {consumer connect. isenabled = false; elastic search. isenabled = true; txtstatus. TEXT = "connected ";});}

In the query button, perform a query object query and bind data in the event reception.

Private void initialize search_click (Object sender, routedeventargs e) {packages. search search = new packages. search (); search. companyName = txtcustomername. text; messageadapter. send (mchannel, search);} private void onreceive (Object sender, eventchannelreceiveargs e) {messageadapter adapter = (messageadapter) E. message; If (adapter. message is packages. searchresult) {packages. searchresult result = (packages. searchresult) adapter. message; this. dispatcher. begininvoke () => {lstcustomers. itemssource = result. MERs MERS ;});}}

This simple user query is complete. It is very easy to use beetle for TCP communication in Windows Phone :)

If you need it, you can go to the http://beetlesl.codeplex.com/get the relevant code

Related Article

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.