Home > Net >  MiniSocket easy-to-use socket TCP development kit the.net core
MiniSocket easy-to-use socket TCP development kit the.net core

Time:09-30

MiniSocket using socket TCP communications, automatic processing of the subcontract to merge, high performance, simple to use, easy to secondary development

The server use: open the vs2017 new.net core (version 2.1 or above) the console application, nuget search MiniSocket download

Code:

The static void Main (string [] args)
{
//actualization server object
The Network server=new Network ();
//set the IP address
Server Ip="127.0.0.1";
//set the port number
Server. The Port=9123;
//set the client maximum number of connections
Server. ClientMaxCnt=10;
//set to receive a timeout
Server. The ReceiveTimeout=1000 * 100;
//set to send timeout
Server. SendTimeout=1000 * 100;
//set the receive buffer size
Server. RecvBufferSize=1024;
//set the number of threads
Server. WorkThreadCnt=20;
//set the client timeout (in seconds)
Server. TimeOver=30;
//set to receive complete event
Server. RecvCompleted +=RecvEventData;
//initialize
Bool bl=server. The Init ();
While (true)
{
Thread.sleep (1000);
}
}

///
///receiving complete event
///

///
///
Private static void RecvEventData (Network e, SocketParas sockArgs)
{

Try
{
String str_head.=Encoding UTF8. Get string (sockArgs. HeadByt);
String str_body.=Encoding UTF8. Get string (sockArgs. BodyByt);

E.S end (sockArgs, Encoding UTF8 GetBytes (" this is the header "), Encoding, UTF8. GetBytes (" this is the body "));
}
The catch (Exception ex)
{
Print (" RecvEventData "+ ex. Message);
}
}

The client use: open the vs2017 new.net framework (version 4.0 or above) the console application, nuget search MiniSocketClient download

Code:

The static void Main (string [] args)
{
//instantiate the client object
The Network client=new Network ();
//set the IP address
Client. Ip="127.0.0.1";
//set the port number
Client. The Port=9123;
//set to receive a timeout
Client. The ReceiveTimeout=1000 * 30;
//set to send timeout
Client. SendTimeout=1000 * 30;
//set the receive buffer size
Client. The ReceiveBufferSize=1024;
//receive complete event
Client. RecvCompleted +=RecvComplete;
//exit event
Client. ExitCompleted +=ExitCompleted;
//initialize
Client. The Init ();
//send the first packet of data
Client. The Send (Encoding UTF8. GetBytes (" hello China "), Encoding, UTF8. GetBytes (" hello world "));

While (true)
{
Thread.sleep (10);
}

}



///
///receiving complete event
///

///
///
Private static void RecvComplete (Network e, SocketParas sockArgs)
{
Try
{

Console. WriteLine (Encoding UTF8. Get string (sockArgs. HeadByt) + Encoding. The UTF8. Get string (sockArgs. BodyByt));
E.S end (Encoding UTF8. GetBytes (" hello world "), Encoding, UTF8. GetBytes (" hello MiniSocket "));
}
The catch (Exception ex)
{
Print (" RecvComplete "+ ex. Message);
}
}

///
///send complete event
///

///
///
Private static void SendComplete (Network e, SocketParas sock)
{

}

///
///exit event
///

///
///
Private static void ExitCompleted (int, string MSG)
{
The switch (state)
{
Normal case 0://
break;
Case 1://connection exception
break;
Case 2://send abnormal
break;
Case 3://receive abnormal
break;
Case 4://manual kicked out
break;
}
}

CodePudding user response:

The type of XXSocket much better ah,

CodePudding user response:

I've more or less contact with some..

Is it has to have at least three callback?

 
Oncon (socket client)

Onmessage (socket client, byte [] data)

Onclose (socket client)


It seems you only the second..

In addition you exit, no client information ah.. At least I also get from List In the clientlist remove...

And you describe the
reference
automatic processing of the subcontract merger


I didn't see the "rules". No rules how to merge your data?

Such as a data beginning have length check.. How did you "dynamic" merger?

CodePudding user response:

to upgrade the subsequent version, on the client, long connection timeout XXX seconds, the server automatically disconnect the connection, the automatic processing of the subcontract to merge this agreement is encapsulated to the internal rules, there is to do data check operation, TCP and orderly, head length and the real data in the internal automatic processing

CodePudding user response:

The client has quit events:
///
///exit event
///

///
///
Private static void ExitCompleted (int, string MSG)
{
The switch (state)
{
Normal case 0://
break;
Case 1://connection exception
break;
Case 2://send abnormal
break;
Case 3://receive abnormal
break;
Case 4://manual kicked out
break;
}
}

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related