Thrift Seventh Lesson C # language Test C + + server

Source: Internet
Author: User

Scene

C # code is now generated through the thrift framework, and because there is no contact with the language, the direct launcher simulates the testing of multiple users. In cases where code cannot be modified for load testing, you can use the system function to start a program that simulates the actual operation of multiple users.


#include <windows.h>


int main ()

{

while (1)

{

:: System ("E:/thriftserver/thrift-csharp/thrifttest/bin/debug/thrifttest.exe");

:: Sleep (1000);

}


return 0;

}


The actual code for C # is as follows

static void ProcessThread (Tprotocol protocol)

{

Tprocessor processor = new Pushmessageservice.processor (new Crecvmessageserviceimpl ());

while (true)

{

Try

{

while (processor. Process (Protocol, Protocol)) {};

Return

}

catch (System.NullReferenceException tt)

{

Return

}

catch (Thrift.Transport.TTransportException tt)

{

This exception is thrown when the server is not started

Return

}

}

}


static void Monitorthread (Ttransport trans, action<string> callback)

{

while (true)

{

Try

{

if (!trans. Peek ())

{

Callback ("Connect close\n");

}

Thread.Sleep (200);

}

catch (Thrift.tapplicationexception ex)

{

Callback (ex. Message);

Return

}

}

}


static void Main (string[] args)

{

Ttransport transport = new Tbufferedtransport (New Tsocket ("192.168.1.110", 7001));

Tprotocol protocol = new Tbinaryprotocol (transport);

Uploadmessageservice.client Client = new uploadmessageservice.client (protocol);

action<tprotocol> processaction = new action<tprotocol> (processthread);

Action<ttransport, action<string>> monitoraction = new Action<ttransport, Action<string>> ( Monitorthread);


Try

{

Transport. Open ();

Processaction.begininvoke (protocol, (result) = =

{

Processaction.endinvoke (result);

}, NULL);


Monitoraction.begininvoke (Transport, (msg) =

{

Console.WriteLine ("Connect Stop", msg);

}, (result) = =

{


}, NULL);



Info. strUserID = "admin";

Info. strpassword = "admin";

Client. Login (info);

}

}

catch (System.NullReferenceException TTX)

{

This exception is thrown when the server stops running

Return

}

catch (System.IO.IOException TTX)

{

Return

}

catch (Thrift.Transport.TTransportException tt)

{

This exception is thrown when the server is not started

Return

}

Transport. Close ();

In this case, the anomaly is not properly closed.

}

}


Thrift Seventh Lesson C # language Test C + + server

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.