├── SSCore
├── .vs
│ └── SSCore
│ │ └── v15
│ │ └── .suo
├── SSCore.Common
│ ├── config.json
│ ├── SSCore.Common.csproj
│ ├── JsonConfigManager.cs
│ ├── BufferManager.cs
│ ├── SmartPool.cs
│ └── SendingQueue.cs
├── SSCore
│ ├── SSCore.csproj.user
│ ├── SSCore.csproj
│ ├── RequestHandler.cs
│ ├── SessionHandler.cs
│ ├── IRequestInfo.cs
│ ├── ISocketServer.cs
│ ├── SocketAsyncEventArgsProxy.cs
│ ├── SocketSession2.cs
│ ├── ISocketSession.cs
│ ├── IAppSession.cs
│ ├── Async.cs
│ ├── IAppServer.cs
│ ├── AsyncSocketSession.cs
│ ├── SocketServerBase.cs
│ ├── IAsyncSocketSession.cs
│ ├── SocketSession.cs
│ └── AppSession.cs
└── SSCore.sln
├── TestServer
├── config.json
├── TestServer.csproj
├── TestServer.csproj.user
└── Program.cs
├── TestClient
├── TestClient.csproj
└── Program.cs
├── LICENSE
├── README.md
└── .gitignore
/SSCore/.vs/SSCore/v15/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/forrestly/SSCore/HEAD/SSCore/.vs/SSCore/v15/.suo
--------------------------------------------------------------------------------
/TestServer/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "server name",
3 | "server_type": "",
4 | "ip": "any",
5 | "port": "2020",
6 | "max_connect": "1000"
7 | }
8 |
--------------------------------------------------------------------------------
/SSCore/SSCore.Common/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "server name",
3 | "server_type": "",
4 | "ip": "any",
5 | "port": "2020",
6 | "max_connect": "1000"
7 | }
8 |
--------------------------------------------------------------------------------
/TestClient/TestClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp1.0
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SSCore/SSCore/SSCore.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/TestServer/TestServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp1.0
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/TestServer/TestServer.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectDebugger
5 |
6 |
7 | TestServer
8 |
9 |
--------------------------------------------------------------------------------
/SSCore/SSCore.Common/SSCore.Common.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp1.0
4 |
5 |
6 |
7 |
8 |
9 |
10 | PreserveNewest
11 |
12 |
13 |
--------------------------------------------------------------------------------
/SSCore/SSCore/SSCore.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp1.0
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/SSCore/SSCore/RequestHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SSCore
6 | {
7 | ///
8 | /// Request handler
9 | ///
10 | /// The type of the app session.
11 | /// The type of the request info.
12 | /// The session.
13 | /// The request info.
14 | public delegate void RequestHandler(TAppSession session, TRequestInfo requestInfo)
15 | where TAppSession : IAppSession, IAppSession, new()
16 | where TRequestInfo : IRequestInfo;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/SSCore/SSCore/SessionHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SSCore
6 | {
7 | ///
8 | /// Used for session level event handler
9 | ///
10 | /// the type of the target session
11 | /// the target session
12 | public delegate void SessionHandler(TAppSession session)
13 | where TAppSession : IAppSession;
14 |
15 | ///
16 | /// Used for session level event handler
17 | ///
18 | /// the type of the target session
19 | /// the target session
20 | /// the target session
21 | /// the event parameter
22 | public delegate void SessionHandler(TAppSession session, TParam value)
23 | where TAppSession : IAppSession;
24 | }
25 |
--------------------------------------------------------------------------------
/TestServer/Program.cs:
--------------------------------------------------------------------------------
1 | using SSCore;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Net.Sockets;
5 |
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | SocketServerBase server = new SocketServerBase();
11 | server.NewClientAccepted += Server_NewClientAccepted;
12 | server.Start();
13 |
14 | Console.WriteLine("enter any key to exit.");
15 | Console.ReadKey();
16 | }
17 |
18 | private static void Server_NewClientAccepted(Socket client, ISocketSession session)
19 | {
20 | Console.WriteLine("----- new client ------------");
21 | AsyncSocketSession ass = session as AsyncSocketSession;
22 |
23 | ass.SetReceiveHandler(arg =>
24 | {
25 | Console.WriteLine("----- new receive ------------");
26 | string received = System.Text.Encoding.UTF8.GetString(arg.Buffer, arg.Offset, arg.BytesTransferred);
27 | Console.WriteLine(received);
28 |
29 | ass.Send(received);
30 | });
31 | }
32 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 forrest
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/SSCore/SSCore/IRequestInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SSCore
6 | {
7 | ///
8 | /// Request information interface
9 | ///
10 | public interface IRequestInfo
11 | {
12 | ///
13 | /// Gets the key of this request.
14 | ///
15 | string Key { get; }
16 | }
17 |
18 | ///
19 | /// Request information interface
20 | ///
21 | /// The type of the request body.
22 | public interface IRequestInfo : IRequestInfo
23 | {
24 | ///
25 | /// Gets the body of this request.
26 | ///
27 | TRequestBody Body { get; }
28 | }
29 |
30 |
31 | ///
32 | /// Request information interface
33 | ///
34 | /// The type of the request header.
35 | /// The type of the request body.
36 | public interface IRequestInfo : IRequestInfo
37 | {
38 | ///
39 | /// Gets the header of the request.
40 | ///
41 | TRequestHeader Header { get; }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SSCore
2 | dotnet core version of SuperSocket. Pick up socket communication logic from SuperSocket, and exclude command concept.
3 |
4 | ## usage
5 |
6 | 1. Create SocketServerBase object
7 | 2. Add handler for new client connection.
8 | 3. Start the socket server object.
9 | 4. Implement the handler of new client connection.
10 | 5. Add handler for receiving message.
11 |
12 | ## Example
13 |
14 |
15 | class Program
16 | {
17 | static void Main(string[] args)
18 | {
19 | SocketServerBase server = new SocketServerBase();
20 | server.NewClientAccepted += Server_NewClientAccepted;
21 | server.Start();
22 |
23 | Console.WriteLine("enter any key to exit.");
24 | Console.ReadKey();
25 | }
26 |
27 | private static void Server_NewClientAccepted(Socket client, ISocketSession session)
28 | {
29 | Console.WriteLine("----- new client ------------");
30 | AsyncSocketSession ass = session as AsyncSocketSession;
31 |
32 | ass.SetReceiveHandler(arg =>
33 | {
34 | Console.WriteLine("----- new receive ------------");
35 | string received = System.Text.Encoding.UTF8.GetString(arg.Buffer, arg.Offset, arg.BytesTransferred);
36 | Console.WriteLine(received);
37 |
38 | ass.Send(received);
39 | });
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SSCore/SSCore/ISocketServer.cs:
--------------------------------------------------------------------------------
1 | using SSCore.Common;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Security.Authentication;
5 | using System.Text;
6 |
7 | namespace SSCore
8 | {
9 | ///
10 | /// It is the basic interface of SocketServer,
11 | /// SocketServer is the abstract server who really listen the comming sockets directly.
12 | ///
13 | public interface ISocketServer
14 | {
15 | ///
16 | /// Starts this instance.
17 | ///
18 | ///
19 | bool Start();
20 |
21 | ///
22 | /// Resets the session's security protocol.
23 | ///
24 | /// The session.
25 | /// The security protocol.
26 | void ResetSessionSecurity(IAppSession session, SslProtocols security);
27 | ///
28 | /// Gets a value indicating whether this instance is running.
29 | ///
30 | ///
31 | /// true if this instance is running; otherwise, false.
32 | ///
33 | bool IsRunning { get; }
34 |
35 | ///
36 | /// Gets the information of the sending queue pool.
37 | ///
38 | ///
39 | /// The sending queue pool.
40 | ///
41 | IPoolInfo SendingQueuePool { get; }
42 |
43 | ///
44 | /// Stops this instance.
45 | ///
46 | void Stop();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/SSCore/SSCore.Common/JsonConfigManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Newtonsoft.Json;
4 | using System.IO;
5 |
6 | namespace SSCore.Common
7 | {
8 | public class JsonConfigManager
9 | {
10 | private static JsonConfigManager _instance;
11 | public static JsonConfigManager Instance
12 | {
13 | get {
14 | if (_instance == null)
15 | _instance = new JsonConfigManager();
16 | return _instance;
17 | }
18 | }
19 |
20 | private Dictionary _configures;
21 | public Dictionary Configures
22 | {
23 | get
24 | {
25 | if (_configures == null)
26 | _configures = ReadConfig();
27 |
28 |
29 | return _configures;
30 | }
31 | }
32 |
33 | private Dictionary ReadConfig()
34 | {
35 | try
36 | {
37 | using (FileStream fs = new FileStream("config.json", FileMode.Open))
38 | {
39 | using (StreamReader sr = new StreamReader(fs))
40 | {
41 | return JsonConvert.DeserializeObject>(sr.ReadToEnd());
42 | }
43 | }
44 | }
45 | catch (Exception ex)
46 | {
47 | throw ex;
48 | }
49 |
50 |
51 | }
52 |
53 |
54 |
55 | private JsonConfigManager()
56 | {
57 | }
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/SSCore/SSCore/SocketAsyncEventArgsProxy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Net.Sockets;
4 | using System.Text;
5 |
6 | namespace SSCore
7 | {
8 | public class SocketAsyncEventArgsProxy
9 | {
10 | public SocketAsyncEventArgs SocketEventArgs { get; private set; }
11 |
12 | public int OrigOffset { get; private set; }
13 |
14 | public bool IsRecyclable { get; private set; }
15 |
16 | private SocketAsyncEventArgsProxy()
17 | {
18 |
19 | }
20 |
21 | public SocketAsyncEventArgsProxy(SocketAsyncEventArgs socketEventArgs)
22 | : this(socketEventArgs, true)
23 | {
24 |
25 | }
26 |
27 | public SocketAsyncEventArgsProxy(SocketAsyncEventArgs socketEventArgs, bool isRecyclable)
28 | {
29 | SocketEventArgs = socketEventArgs;
30 | OrigOffset = socketEventArgs.Offset;
31 | SocketEventArgs.Completed += new EventHandler(SocketEventArgs_Completed);
32 | IsRecyclable = isRecyclable;
33 | }
34 |
35 | static void SocketEventArgs_Completed(object sender, SocketAsyncEventArgs e)
36 | {
37 | var socketSession = e.UserToken as IAsyncSocketSession;
38 |
39 | if (socketSession == null)
40 | return;
41 |
42 | if (e.LastOperation == SocketAsyncOperation.Receive)
43 | {
44 | socketSession.AsyncRun(() => socketSession.ProcessReceive(e));
45 | }
46 | else
47 | {
48 | throw new ArgumentException("The last operation completed on the socket was not a receive");
49 | }
50 | }
51 |
52 | public void Initialize(IAsyncSocketSession socketSession)
53 | {
54 | SocketEventArgs.UserToken = socketSession;
55 | }
56 |
57 | public void Reset()
58 | {
59 | SocketEventArgs.UserToken = null;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/TestClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Sockets;
3 |
4 | class Program
5 | {
6 | static void Main(string[] args)
7 | {
8 | StartAsync();
9 | }
10 |
11 | static void StartAsync()
12 | {
13 |
14 | Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
15 |
16 | try
17 | {
18 | client.Connect("127.0.0.1", 2020);
19 | }
20 | catch (Exception ex)
21 | {
22 | throw ex;
23 | }
24 | while (true)
25 | {
26 | //try
27 | //{
28 | // client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
29 | // client.Connect("127.0.0.1", 2020);
30 | //}
31 | //catch (Exception ex)
32 | //{
33 | // throw ex;
34 | //}
35 |
36 | try
37 | {
38 | client.Send(System.Text.Encoding.UTF8.GetBytes("hello world!"));
39 | }
40 | catch (Exception)
41 | {
42 | Console.WriteLine("send error.");
43 | }
44 | Console.WriteLine("sent message.");
45 | var buffer = new byte[128];
46 | try
47 | {
48 | client.Receive(buffer);
49 | }
50 | catch (Exception)
51 | {
52 | Console.WriteLine("receive error.");
53 | }
54 | Console.WriteLine("received message.");
55 | Console.WriteLine(System.Text.Encoding.UTF8.GetString(buffer, 0, 12));
56 |
57 | var key = Console.ReadKey();
58 |
59 | if (key.KeyChar.Equals('q'))
60 | break;
61 |
62 | Console.WriteLine("any key to continue, press q to exit.");
63 | //try
64 | //{
65 | // Console.WriteLine("---Close Client.---");
66 | // client.Shutdown(SocketShutdown.Both);
67 | // client.Dispose();
68 | //}
69 | //catch (Exception)
70 | //{
71 | // Console.WriteLine("Shundown Error");
72 | //}
73 |
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/SSCore/SSCore.Common/BufferManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Net.Sockets;
4 | using System.Text;
5 |
6 | namespace SSCore.Common
7 | {
8 | ///
9 | /// This class creates a single large buffer which can be divided up and assigned to SocketAsyncEventArgs objects for use
10 | /// with each socket I/O operation. This enables bufffers to be easily reused and gaurds against fragmenting heap memory.
11 | ///
12 | /// The operations exposed on the BufferManager class are not thread safe.
13 | ///
14 | public class BufferManager
15 | {
16 | int m_numBytes; // the total number of bytes controlled by the buffer pool
17 | byte[] m_buffer; // the underlying byte array maintained by the Buffer Manager
18 | Stack m_freeIndexPool; //
19 | int m_currentIndex;
20 | int m_bufferSize;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// The total bytes.
26 | /// Size of the buffer.
27 | public BufferManager(int totalBytes, int bufferSize)
28 | {
29 | m_numBytes = totalBytes;
30 | m_currentIndex = 0;
31 | m_bufferSize = bufferSize;
32 | m_freeIndexPool = new Stack();
33 | }
34 |
35 | ///
36 | /// Allocates buffer space used by the buffer pool
37 | ///
38 | public void InitBuffer()
39 | {
40 | // create one big large buffer and divide that out to each SocketAsyncEventArg object
41 | m_buffer = new byte[m_numBytes];
42 | }
43 |
44 | ///
45 | /// Assigns a buffer from the buffer pool to the specified SocketAsyncEventArgs object
46 | ///
47 | /// true if the buffer was successfully set, else false
48 | public bool SetBuffer(SocketAsyncEventArgs args)
49 | {
50 |
51 | if (m_freeIndexPool.Count > 0)
52 | {
53 | args.SetBuffer(m_buffer, m_freeIndexPool.Pop(), m_bufferSize);
54 | }
55 | else
56 | {
57 | if ((m_numBytes - m_bufferSize) < m_currentIndex)
58 | {
59 | return false;
60 | }
61 | args.SetBuffer(m_buffer, m_currentIndex, m_bufferSize);
62 | m_currentIndex += m_bufferSize;
63 | }
64 | return true;
65 | }
66 |
67 | ///
68 | /// Removes the buffer from a SocketAsyncEventArg object. This frees the buffer back to the
69 | /// buffer pool
70 | ///
71 | public void FreeBuffer(SocketAsyncEventArgs args)
72 | {
73 | m_freeIndexPool.Push(args.Offset);
74 | args.SetBuffer(null, 0, 0);
75 | }
76 |
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/SSCore/SSCore/SocketSession2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.CompilerServices;
4 | using System.Text;
5 |
6 | namespace SSCore
7 | {
8 | public abstract partial class SocketSession
9 | {
10 | private const string m_GeneralErrorMessage = "Unexpected error";
11 | private const string m_GeneralSocketErrorMessage = "Unexpected socket error: {0}";
12 | private const string m_CallerInformation = "Caller: {0}, file path: {1}, line number: {2}";
13 |
14 | ///
15 | /// Logs the error, skip the ignored exception
16 | ///
17 | /// The exception.
18 | /// The caller.
19 | /// The caller file path.
20 | /// The caller line number.
21 | protected void LogError(Exception exception, [CallerMemberName] string caller = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
22 | {
23 | int socketErrorCode;
24 |
25 | //This exception is ignored, needn't log it
26 | //if (IsIgnorableException(exception, out socketErrorCode))
27 | // return;
28 |
29 | //var message = socketErrorCode > 0 ? string.Format(m_GeneralSocketErrorMessage, socketErrorCode) : m_GeneralErrorMessage;
30 |
31 | //AppSession.Logger.Error(this
32 | // , message + Environment.NewLine + string.Format(m_CallerInformation, caller, callerFilePath, callerLineNumber)
33 | // , exception);
34 | }
35 |
36 | ///
37 | /// Logs the error, skip the ignored exception
38 | ///
39 | /// The message.
40 | /// The exception.
41 | /// The caller.
42 | /// The caller file path.
43 | /// The caller line number.
44 | protected void LogError(string message, Exception exception, [CallerMemberName] string caller = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
45 | {
46 | int socketErrorCode;
47 |
48 | //This exception is ignored, needn't log it
49 | //if (IsIgnorableException(exception, out socketErrorCode))
50 | // return;
51 |
52 | //AppSession.Logger.Error(this
53 | // , message + Environment.NewLine + string.Format(m_CallerInformation, caller, callerFilePath, callerLineNumber)
54 | // , exception);
55 | }
56 |
57 | ///
58 | /// Logs the socket error, skip the ignored error
59 | ///
60 | /// The socket error code.
61 | /// The caller.
62 | /// The caller file path.
63 | /// The caller line number.
64 | protected void LogError(int socketErrorCode, [CallerMemberName] string caller = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
65 | {
66 | //if (!Config.LogAllSocketException)
67 | //{
68 | // //This error is ignored, needn't log it
69 | // if (IsIgnorableSocketError(socketErrorCode))
70 | // return;
71 | //}
72 |
73 | //AppSession.Logger.Error(this
74 | // , string.Format(m_GeneralSocketErrorMessage, socketErrorCode) + Environment.NewLine + string.Format(m_CallerInformation, caller, callerFilePath, callerLineNumber)
75 | // , new SocketException(socketErrorCode));
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/SSCore/SSCore/ISocketSession.cs:
--------------------------------------------------------------------------------
1 | using SSCore.Common;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Net;
5 | using System.Net.Sockets;
6 | using System.Security.Authentication;
7 | using System.Text;
8 |
9 | namespace SSCore
10 | {
11 | ///
12 | /// CloseReason enum
13 | ///
14 | public enum CloseReason : int
15 | {
16 | ///
17 | /// The socket is closed for unknown reason
18 | ///
19 | Unknown = 0,
20 |
21 | ///
22 | /// Close for server shutdown
23 | ///
24 | ServerShutdown = 1,
25 |
26 | ///
27 | /// The client close the socket
28 | ///
29 | ClientClosing = 2,
30 |
31 | ///
32 | /// The server side close the socket
33 | ///
34 | ServerClosing = 3,
35 |
36 | ///
37 | /// Application error
38 | ///
39 | ApplicationError = 4,
40 |
41 | ///
42 | /// The socket is closed for a socket error
43 | ///
44 | SocketError = 5,
45 |
46 | ///
47 | /// The socket is closed by server for timeout
48 | ///
49 | TimeOut = 6,
50 |
51 | ///
52 | /// Protocol error
53 | ///
54 | ProtocolError = 7,
55 |
56 | ///
57 | /// SuperSocket internal error
58 | ///
59 | InternalError = 8,
60 | }
61 |
62 | ///
63 | /// The interface for socket session
64 | ///
65 | public interface ISocketSession : ISessionBase
66 | {
67 | ///
68 | /// Initializes the specified app session.
69 | ///
70 | /// The app session.
71 | void Initialize(IAppSession appSession);
72 |
73 | void InitializeSendingQueue(ISmartPool pool);
74 |
75 | ///
76 | /// Starts this instance.
77 | ///
78 | void Start();
79 |
80 | ///
81 | /// Closes the socket session for the specified reason.
82 | ///
83 | /// The reason.
84 | void Close(CloseReason reason);
85 |
86 |
87 | ///
88 | /// Tries to send array segment.
89 | ///
90 | /// The segments.
91 | bool TrySend(IList> segments);
92 |
93 | ///
94 | /// Tries to send array segment.
95 | ///
96 | /// The segment.
97 | bool TrySend(ArraySegment segment);
98 |
99 | ///
100 | /// Applies the secure protocol.
101 | ///
102 | void ApplySecureProtocol();
103 |
104 | ///
105 | /// Gets the client socket.
106 | ///
107 | Socket Client { get; }
108 |
109 | ///
110 | /// Gets the local listening endpoint.
111 | ///
112 | IPEndPoint LocalEndPoint { get; }
113 |
114 | ///
115 | /// Gets or sets the secure protocol.
116 | ///
117 | ///
118 | /// The secure protocol.
119 | ///
120 | SslProtocols SecureProtocol { get; set; }
121 |
122 | ///
123 | /// Occurs when [closed].
124 | ///
125 | Action Closed { get; set; }
126 |
127 | ///
128 | /// Gets the app session assosiated with this socket session.
129 | ///
130 | IAppSession AppSession { get; }
131 |
132 |
133 | ///
134 | /// Gets the original receive buffer offset.
135 | ///
136 | ///
137 | /// The original receive buffer offset.
138 | ///
139 | int OrigReceiveOffset { get; }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/SSCore/SSCore/IAppSession.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Net;
4 | using System.Text;
5 |
6 | namespace SSCore
7 | {
8 | ///
9 | /// The basic session interface
10 | ///
11 | public interface ISessionBase
12 | {
13 | ///
14 | /// Gets the session ID.
15 | ///
16 | string SessionID { get; }
17 |
18 | ///
19 | /// Gets the remote endpoint.
20 | ///
21 | IPEndPoint RemoteEndPoint { get; }
22 | }
23 |
24 | ///
25 | /// The basic interface for appSession
26 | ///
27 | public interface IAppSession : ISessionBase
28 | {
29 | ///
30 | /// Gets the app server.
31 | ///
32 | IAppServer AppServer { get; }
33 | ///
34 | /// Gets the socket session of the AppSession.
35 | ///
36 | ISocketSession SocketSession { get; }
37 |
38 | ///
39 | /// Gets the items.
40 | ///
41 | IDictionary