Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit 7660b3f

Browse files
authored
Update README.md
1 parent 62cb8da commit 7660b3f

1 file changed

Lines changed: 79 additions & 3 deletions

File tree

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,82 @@ https://www.nuget.org/packages/MossbauerLab.TinyTcpServer.Core/
2727

2828
# 4. FULL EXAMPLE OF HOW TO USE
2929

30-
Contributors
31-
EvilLord666 aka Ushakov Michael
32-
KatanaZZZ aka Anonymous
30+
private const String LocalIpAddress = "127.0.0.1";
31+
private const UInt16 ServerPort = 8044;
32+
private const String Script = @"..\..\TestScripts\SimpleScript.cs";
33+
34+
private ITcpServer _server;
35+
36+
public void Init()
37+
{
38+
_server = new FlexibleTcpServer(Script, LocalIpAddress, ServerPort);
39+
}
40+
41+
That is all ! all logics is inside you script
42+
There are requirement to presence of initial class and entry method
43+
44+
public class ServerScript
45+
{
46+
public void Init(ref ITcpServer server)
47+
{
48+
if(server == null)
49+
throw new NullReferenceException("server");
50+
_server = server;
51+
_connectHandlerId = Guid.NewGuid();
52+
_dataHandlerId = Guid.NewGuid();
53+
//Console.WriteLine("Init....");
54+
_server.AddConnectionHandler(_connectHandlerId, OnClientConnection);
55+
_server.AddHandler(new TcpClientHandlerInfo(_dataHandlerId), OnClientExchange);
56+
}
57+
// ...
58+
}
59+
60+
// in this method we set up handlers
61+
Handlers on Connect and Exchange looks like:
62+
public Byte[] OnClientExchange(Byte[] receivedData, TcpClientHandlerInfo info)
63+
{
64+
lock (receivedData)
65+
{
66+
Byte[] outputData = new Byte[receivedData.Length];
67+
Array.Copy(receivedData, outputData, receivedData.Length);
68+
return outputData;
69+
}
70+
}
71+
72+
public void OnClientConnection(TcpClientContext context, Boolean connect) // connect true if client connected and false if disconnected
73+
{
74+
75+
}
76+
77+
Full example present (in file SimpleScript inside MossbauerLab.TinyTcpServer.FunctionalTests
78+
79+
# 5 Expanded setting
80+
There are additional settings for TcpServer -> see class TcpServerSettings.cs (MossbauerLab.TinyTcpServer.Core)
81+
In Console project there is a class that could parse config ftle (key=value) with that settings class is TcpServerConfigBuilder
82+
83+
it handles file, examples of settings:
84+
# This is a example of settings file all settings are represented as pair key=value, lines started from # are commentary (ignores)
85+
# number of clients processing the 'same time'
86+
ParallelTask = 256
87+
# buffer on receive for every client (in bytes)
88+
ClientBufferSize = 65535
89+
# chunk is a auant of size for read and write operations
90+
ChunkSize = 4096
91+
# number of times in a row that calls BeginAccept (in a sepatarate from IO processing thread)
92+
ClientConnectAttempts = 4
93+
# time while client stays inactive, after this time is off (in seconds) client will be disconneced by server
94+
ClientInactivityTime = 120
95+
# timeout for BeginAccept in milliseconds
96+
ClientConnectTimeout = 1000
97+
# number of attempts in a row to get data from client
98+
ClientReadAttempts = 8
99+
# timeout in milliseconds on every read attemp
100+
ReadTimeout = 200
101+
# timeout in milliseconds for server to shutdown, close all opened resources
102+
ServerCloseTimeout = 2000
103+
# timeout in milliseconds to complete write operation
104+
WriteTimeout = 1000
105+
106+
# 6 CONTRIBUTORS
107+
EvilLord666 aka Ushakov Michael
108+
KatanaZZZ aka Anonymous

0 commit comments

Comments
 (0)