SocketServerFactory.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.SocketBase;
  6. using SuperSocket.SocketBase.Protocol;
  7. using SuperSocket.SocketBase.Config;
  8. using System.Net;
  9. namespace SuperSocket.SocketEngine
  10. {
  11. /// <summary>
  12. /// Default socket server factory
  13. /// </summary>
  14. public class SocketServerFactory : ISocketServerFactory
  15. {
  16. #region ISocketServerFactory Members
  17. /// <summary>
  18. /// Creates the socket server.
  19. /// </summary>
  20. /// <typeparam name="TRequestInfo">The type of the request info.</typeparam>
  21. /// <param name="appServer">The app server.</param>
  22. /// <param name="listeners">The listeners.</param>
  23. /// <param name="config">The config.</param>
  24. /// <returns></returns>
  25. public ISocketServer CreateSocketServer<TRequestInfo>(IAppServer appServer, ListenerInfo[] listeners, IServerConfig config)
  26. where TRequestInfo : IRequestInfo
  27. {
  28. if (appServer == null)
  29. throw new ArgumentNullException("appServer");
  30. if (listeners == null)
  31. throw new ArgumentNullException("listeners");
  32. if (config == null)
  33. throw new ArgumentNullException("config");
  34. switch(config.Mode)
  35. {
  36. case(SocketMode.Tcp):
  37. return new AsyncSocketServer(appServer, listeners);
  38. case(SocketMode.Udp):
  39. return new UdpSocketServer<TRequestInfo>(appServer, listeners);
  40. default:
  41. throw new NotSupportedException("Unsupported SocketMode:" + config.Mode);
  42. }
  43. }
  44. #endregion
  45. }
  46. }