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