1 | #Region "Microsoft.VisualBasic::d2c9a815a23622c9e4141f970511d85b, Microsoft.VisualBasic.Core\Net\Tcp\Persistent\Socket\WorkSocket.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Class WorkSocket |
35 | ' |
36 | ' Constructor: (+1 Overloads) Sub New |
37 | ' Sub: (+2 Overloads) PushMessage, ReadCallback |
38 | ' |
39 | ' |
40 | ' /********************************************************************************/ |
41 | |
42 | #End Region |
43 | |
44 | Imports System.Net.Sockets |
45 | Imports System.Runtime.CompilerServices |
46 | Imports Microsoft.VisualBasic.ApplicationServices.Debugging.ExceptionExtensions |
47 | Imports Microsoft.VisualBasic.Net.Abstract |
48 | Imports Microsoft.VisualBasic.Net.Protocols |
49 | |
50 | Namespace Net.Tcp.Persistent.Socket |
51 | |
52 | ''' <summary> |
53 | ''' 长连接之中只是进行消息的发送处理,并不保证数据能够被接收到 |
54 | ''' </summary> |
55 | Public Class WorkSocket : Inherits StateObject |
56 | |
57 | Public ExceptionHandle As ExceptionHandler |
58 | Public ForceCloseHandle As ForceCloseHandle |
59 | Public TotalBytes As Double |
60 | |
61 | Public ReadOnly ConnectTime As Date = Now |
62 | |
63 | Sub New(Socket As StateObject) |
64 | Me.ChunkBuffer = Socket.ChunkBuffer |
65 | Me.readBuffer = Socket.readBuffer |
66 | Me.workSocket = Socket.workSocket |
67 | End Sub |
68 | |
69 | ''' <summary> |
70 | ''' DO_NOTHING |
71 | ''' </summary> |
72 | ''' <param name="ar"></param> |
73 | Public Sub ReadCallback(ar As IAsyncResult) |
74 | ' DO_NOTHING |
75 | End Sub 'ReadCallback |
76 | |
77 | ''' <summary> |
78 | ''' Server send message to user client. |
79 | ''' </summary> |
80 | ''' <param name="request"></param> |
81 | Public Sub PushMessage(request As RequestStream) |
82 | Dim byteData As Byte() = request.Serialize |
83 | Try |
84 | Call Me.workSocket.Send(byteData, byteData.Length, SocketFlags.None) |
85 | Catch ex As Exception |
86 | Call ForceCloseHandle(Me) |
87 | End Try |
88 | End Sub |
89 | |
90 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
91 | Public Sub PushMessage(message As String) |
92 | Call PushMessage(New RequestStream(message)) |
93 | End Sub |
94 | End Class |
95 | End Namespace |