Skip to content

Commit ccd44f9

Browse files
committed
added new configuration attribute "protocol"
1 parent de86c41 commit ccd44f9

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed

SocketBase/AppServer.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,19 @@ public AppServer(IReceiveFilterFactory<StringPackageInfo> receiveFilterFactory)
7272

7373
internal override IReceiveFilterFactory<StringPackageInfo> CreateDefaultReceiveFilterFactory()
7474
{
75-
return new CommandLineReceiveFilterFactory(TextEncoding);
75+
var config = Config;
76+
77+
if(config.Protocol == ProtocolMode.CommandLine)
78+
return new CommandLineReceiveFilterFactory(TextEncoding);
79+
else if (config.Protocol == ProtocolMode.WebSocket)
80+
{
81+
var websocketReceiveFilterFactoryType =
82+
Type.GetType("SuperSocket.WebSocket.WebSocketReceiveFilterFactory, SuperSocket.WebSocket");
83+
84+
return (IReceiveFilterFactory<StringPackageInfo>)Activator.CreateInstance(websocketReceiveFilterFactoryType);
85+
}
86+
87+
return null;
7688
}
7789
}
7890
}

SocketBase/Config/IServerConfig.cs

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public partial interface IServerConfig
2828
/// </value>
2929
string ServerType { get; }
3030

31+
/// <summary>
32+
/// Gets the protocol the server instance want to use.
33+
/// </summary>
34+
/// <value>
35+
/// The protocol the server instance want to use.
36+
/// </value>
37+
ProtocolMode Protocol { get; }
38+
3139
/// <summary>
3240
/// Gets the Receive filter factory.
3341
/// </summary>

SocketBase/Config/ServerConfig.cs

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ public ServerConfig()
134134
/// </value>
135135
public string ServerType { get; set; }
136136

137+
/// <summary>
138+
/// Gets/sets the protocol the server instance want to use.
139+
/// </summary>
140+
/// <value>
141+
/// The protocol the server instance want to use.
142+
/// </value>
143+
public ProtocolMode Protocol { get; set; }
144+
137145
/// <summary>
138146
/// Gets/sets the Receive filter factory.
139147
/// </summary>

SocketBase/ProtocolMode.cs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SuperSocket.SocketBase
8+
{
9+
/// <summary>
10+
/// Application protocol mode
11+
/// </summary>
12+
public enum ProtocolMode
13+
{
14+
/// <summary>
15+
/// The command line protocol
16+
/// </summary>
17+
CommandLine,
18+
/// <summary>
19+
/// The web socket protocol
20+
/// </summary>
21+
WebSocket,
22+
/// <summary>
23+
/// The custom protocol defined by yourself
24+
/// </summary>
25+
Custom
26+
}
27+
}

SocketBase/SuperSocket.SocketBase.Net45.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<Compile Include="Pool\IPool.cs" />
127127
<Compile Include="Pool\IPoolItemCreator.cs" />
128128
<Compile Include="Pool\NullBufferManager.cs" />
129+
<Compile Include="ProtocolMode.cs" />
129130
<Compile Include="Protocol\CommandLineReceiveFilterFactory.cs" />
130131
<Compile Include="Protocol\CountSpliterReceiveFilter.cs" />
131132
<Compile Include="Protocol\CountSpliterReceiveFilterFactory.cs" />

SocketEngine/Configuration/Server.cs

+12
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ public SocketMode Mode
7878
get { return (SocketMode)this["mode"]; }
7979
}
8080

81+
/// <summary>
82+
/// Gets the protocol the server instance want to use.
83+
/// </summary>
84+
/// <value>
85+
/// The protocol the server instance want to use.
86+
/// </value>
87+
[ConfigurationProperty("protocol", IsRequired = false, DefaultValue = "CommandLine")]
88+
public ProtocolMode Protocol
89+
{
90+
get { return (ProtocolMode)this["protocol"]; }
91+
}
92+
8193

8294
/// <summary>
8395
/// Gets the request handling mode.

0 commit comments

Comments
 (0)