forked from kerryjiang/SuperSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketServerFactory.cs
More file actions
58 lines (51 loc) · 1.89 KB
/
Copy pathSocketServerFactory.cs
File metadata and controls
58 lines (51 loc) · 1.89 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Net;
using System.Text;
using SuperSocket.ProtoBase;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Protocol;
using SuperSocket.SocketBase.Provider;
namespace SuperSocket.SocketEngine
{
/// <summary>
/// Default socket server factory
/// </summary>
[Export(typeof(ISocketServerFactory))]
[ProviderMetadata("SocketServerFactory")]
public class SocketServerFactory : ISocketServerFactory
{
#region ISocketServerFactory Members
/// <summary>
/// Creates the socket server.
/// </summary>
/// <typeparam name="TPackageInfo">The type of the request info.</typeparam>
/// <param name="appServer">The app server.</param>
/// <param name="listeners">The listeners.</param>
/// <param name="config">The config.</param>
/// <returns></returns>
public ISocketServer CreateSocketServer<TPackageInfo>(IAppServer appServer, ListenerInfo[] listeners, IServerConfig config)
where TPackageInfo : IPackageInfo
{
if (appServer == null)
throw new ArgumentNullException("appServer");
if (listeners == null)
throw new ArgumentNullException("listeners");
if (config == null)
throw new ArgumentNullException("config");
switch(config.Mode)
{
case(SocketMode.Tcp):
return new AsyncSocketServer(appServer, listeners);
case(SocketMode.Udp):
return new UdpSocketServer<TPackageInfo>(appServer, listeners);
default:
throw new NotSupportedException("Unsupported SocketMode:" + config.Mode);
}
}
#endregion
}
}