forked from hiram3512/HiSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.cs
More file actions
41 lines (36 loc) · 1.24 KB
/
Example2.cs
File metadata and controls
41 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/***************************************************************
* Description:
*
* Documents: https://github.com/hiramtan/HiSocket
* Author: hiramtan@live.com
***************************************************************/
using System;
using HiSocket.Tcp;
namespace HiSocket.Example
{
class Example2
{
TcpConnection tcp;
void Connect()
{
tcp = new TcpConnection(new PackageExample());
tcp.OnDisconnected += OnDisconnect;
tcp.Connect("127.0.0.1", 999);
tcp.Socket.NoDelay = true;
tcp.Socket.SendTimeout = 100;
tcp.Socket.ReceiveTimeout = 200;
//...
// you can add plugin sub from IPlugins
tcp.AddPlugin(new StatisticalPlugin("Statistical"));//this plugin calculate how many send
}
void OnDisconnect()
{
var length = tcp.SendBuffer.WritePosition;
Console.WriteLine("Still have {0} not send to server when abnormal shutdown");
var data = tcp.SendBuffer.Read(length);
tcp.SendBuffer.ResetIndex();
//use can handle these data, for example maybe can send next time when connect again
//tcp.Send(data);
}
}
}