FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow Customizing Socket Creation in TCPClient #90 · StudyWithJeffrey/NetCoreServer@2312a1d · GitHub

Repository navigation

Commit 2312a1d

Browse files
committed
Allow Customizing Socket Creation in TCPClient chronoxor#90
1 parent fea66f9 commit 2312a1d

8 files changed

Lines changed: 82 additions & 10 deletions

File tree

‎.appveyor.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Specify version format
2-
version: "3.0.20.{build}"
2+
version: "3.0.21.{build}"
33

44
# Image to use
55
image: Visual Studio 2019

‎source/NetCoreServer/NetCoreServer.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
5-
<Version>3.0.20</Version>
5+
<Version>3.0.21</Version>
66
<Authors>Ivan Shynkarenka</Authors>
77
<Copyright>Copyright (c) 2019-2020 Ivan Shynkarenka</Copyright>
88
<RepositoryUrl>https://github.com/chronoxor/NetCoreServer</RepositoryUrl>

‎source/NetCoreServer/SslClient.cs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ public SslClient(SslContext context, IPEndPoint endpoint)
136136
/// </summary>
137137
public bool IsHandshaked { get; private set; }
138138

139+
/// <summary>
140+
/// Create a new socket object
141+
/// </summary>
142+
/// <remarks>
143+
/// Method may be override if you need to prepare some specific socket object in your implementation.
144+
/// </remarks>
145+
/// <returns>Socket object</returns>
146+
protected virtual Socket CreateSocket()
147+
{
148+
return new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
149+
}
150+
139151
/// <summary>
140152
/// Connect the client (synchronous)
141153
/// </summary>
@@ -160,7 +172,7 @@ public virtual bool Connect()
160172
_connectEventArg.Completed += OnAsyncCompleted;
161173

162174
// Create a new client socket
163-
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
175+
Socket = CreateSocket();
164176

165177
// Apply the option: dual mode (this option must be applied before connecting)
166178
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
@@ -356,7 +368,7 @@ public virtual bool ConnectAsync()
356368
_connectEventArg.Completed += OnAsyncCompleted;
357369

358370
// Create a new client socket
359-
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
371+
Socket = CreateSocket();
360372

361373
// Apply the option: dual mode (this option must be applied before connecting)
362374
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)

‎source/NetCoreServer/SslServer.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ public SslServer(SslContext context, IPEndPoint endpoint)
144144
/// </summary>
145145
public bool IsAccepting { get; private set; }
146146

147+
/// <summary>
148+
/// Create a new socket object
149+
/// </summary>
150+
/// <remarks>
151+
/// Method may be override if you need to prepare some specific socket object in your implementation.
152+
/// </remarks>
153+
/// <returns>Socket object</returns>
154+
protected virtual Socket CreateSocket()
155+
{
156+
return new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
157+
}
158+
147159
/// <summary>
148160
/// Start the server
149161
/// </summary>
@@ -159,7 +171,7 @@ public virtual bool Start()
159171
_acceptorEventArg.Completed += OnAsyncCompleted;
160172

161173
// Create a new acceptor socket
162-
_acceptorSocket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
174+
_acceptorSocket = CreateSocket();
163175

164176
// Update the acceptor socket disposed flag
165177
IsSocketDisposed = false;

‎source/NetCoreServer/TcpClient.cs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ public TcpClient(IPEndPoint endpoint)
110110
/// </summary>
111111
public bool IsConnected { get; private set; }
112112

113+
/// <summary>
114+
/// Create a new socket object
115+
/// </summary>
116+
/// <remarks>
117+
/// Method may be override if you need to prepare some specific socket object in your implementation.
118+
/// </remarks>
119+
/// <returns>Socket object</returns>
120+
protected virtual Socket CreateSocket()
121+
{
122+
return new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
123+
}
124+
113125
/// <summary>
114126
/// Connect the client (synchronous)
115127
/// </summary>
@@ -138,7 +150,7 @@ public virtual bool Connect()
138150
_sendEventArg.Completed += OnAsyncCompleted;
139151

140152
// Create a new client socket
141-
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
153+
Socket = CreateSocket();
142154

143155
// Apply the option: dual mode (this option must be applied before connecting)
144156
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
@@ -295,7 +307,7 @@ public virtual bool ConnectAsync()
295307
_sendEventArg.Completed += OnAsyncCompleted;
296308

297309
// Create a new client socket
298-
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
310+
Socket = CreateSocket();
299311

300312
// Apply the option: dual mode (this option must be applied before connecting)
301313
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)

‎source/NetCoreServer/TcpServer.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ public TcpServer(IPEndPoint endpoint)
135135
/// </summary>
136136
public bool IsAccepting { get; private set; }
137137

138+
/// <summary>
139+
/// Create a new socket object
140+
/// </summary>
141+
/// <remarks>
142+
/// Method may be override if you need to prepare some specific socket object in your implementation.
143+
/// </remarks>
144+
/// <returns>Socket object</returns>
145+
protected virtual Socket CreateSocket()
146+
{
147+
return new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
148+
}
149+
138150
/// <summary>
139151
/// Start the server
140152
/// </summary>
@@ -150,7 +162,7 @@ public virtual bool Start()
150162
_acceptorEventArg.Completed += OnAsyncCompleted;
151163

152164
// Create a new acceptor socket
153-
_acceptorSocket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
165+
_acceptorSocket = CreateSocket();
154166

155167
// Update the acceptor socket disposed flag
156168
IsSocketDisposed = false;

‎source/NetCoreServer/UdpClient.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ public UdpClient(IPEndPoint endpoint)
115115
/// </summary>
116116
public bool IsConnected { get; private set; }
117117

118+
/// <summary>
119+
/// Create a new socket object
120+
/// </summary>
121+
/// <remarks>
122+
/// Method may be override if you need to prepare some specific socket object in your implementation.
123+
/// </remarks>
124+
/// <returns>Socket object</returns>
125+
protected virtual Socket CreateSocket()
126+
{
127+
return new Socket(Endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
128+
}
129+
118130
/// <summary>
119131
/// Connect the client (synchronous)
120132
/// </summary>
@@ -135,7 +147,7 @@ public virtual bool Connect()
135147
_sendEventArg.Completed += OnAsyncCompleted;
136148

137149
// Create a new client socket
138-
Socket = new Socket(Endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
150+
Socket = CreateSocket();
139151

140152
// Update the client socket disposed flag
141153
IsSocketDisposed = false;

‎source/NetCoreServer/UdpServer.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ public UdpServer(IPEndPoint endpoint)
116116
/// </summary>
117117
public bool IsStarted { get; private set; }
118118

119+
/// <summary>
120+
/// Create a new socket object
121+
/// </summary>
122+
/// <remarks>
123+
/// Method may be override if you need to prepare some specific socket object in your implementation.
124+
/// </remarks>
125+
/// <returns>Socket object</returns>
126+
protected virtual Socket CreateSocket()
127+
{
128+
return new Socket(Endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
129+
}
130+
119131
/// <summary>
120132
/// Start the server (synchronous)
121133
/// </summary>
@@ -137,7 +149,7 @@ public virtual bool Start()
137149
_sendEventArg.Completed += OnAsyncCompleted;
138150

139151
// Create a new server socket
140-
Socket = new Socket(Endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
152+
Socket = CreateSocket();
141153

142154
// Update the server socket disposed flag
143155
IsSocketDisposed = false;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL