2019-05-22 19:02:42 +08:00
|
|
|
|
#Region "Microsoft.VisualBasic::d2c9a815a23622c9e4141f970511d85b, Microsoft.VisualBasic.Core\Net\Tcp\Persistent\Socket\WorkSocket.vb"
|
2018-10-06 01:51:08 +08:00
|
|
|
|
|
2018-10-06 16:50:20 +08:00
|
|
|
|
' Author:
|
|
|
|
|
|
'
|
|
|
|
|
|
' asuka (amethyst.asuka@gcmodeller.org)
|
|
|
|
|
|
' xie (genetics@smrucc.org)
|
|
|
|
|
|
' xieguigang (xie.guigang@live.com)
|
|
|
|
|
|
'
|
|
|
|
|
|
' Copyright (c) 2018 GPL3 Licensed
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' GNU GENERAL PUBLIC LICENSE (GPL3)
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
' it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
' the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
' (at your option) any later version.
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
' GNU General Public License for more details.
|
|
|
|
|
|
'
|
|
|
|
|
|
' You should have received a copy of the GNU General Public License
|
|
|
|
|
|
' along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-10-06 16:14:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-06 16:50:20 +08:00
|
|
|
|
' /********************************************************************************/
|
2018-10-06 16:14:58 +08:00
|
|
|
|
|
2018-10-06 16:50:20 +08:00
|
|
|
|
' Summaries:
|
2018-10-06 16:14:58 +08:00
|
|
|
|
|
2018-10-06 16:50:20 +08:00
|
|
|
|
' Class WorkSocket
|
|
|
|
|
|
'
|
|
|
|
|
|
' Constructor: (+1 Overloads) Sub New
|
|
|
|
|
|
' Sub: (+2 Overloads) PushMessage, ReadCallback
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' /********************************************************************************/
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
|
|
Imports System.Net.Sockets
|
2018-10-06 16:14:58 +08:00
|
|
|
|
Imports System.Runtime.CompilerServices
|
2018-10-06 01:10:12 +08:00
|
|
|
|
Imports Microsoft.VisualBasic.ApplicationServices.Debugging.ExceptionExtensions
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Imports Microsoft.VisualBasic.Net.Abstract
|
|
|
|
|
|
Imports Microsoft.VisualBasic.Net.Protocols
|
|
|
|
|
|
|
2018-10-06 01:35:38 +08:00
|
|
|
|
Namespace Net.Tcp.Persistent.Socket
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' 长连接之中只是进行消息的发送处理,并不保证数据能够被接收到
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
Public Class WorkSocket : Inherits StateObject
|
2018-10-05 15:51:33 +08:00
|
|
|
|
|
|
|
|
|
|
Public ExceptionHandle As ExceptionHandler
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Public ForceCloseHandle As ForceCloseHandle
|
|
|
|
|
|
Public TotalBytes As Double
|
|
|
|
|
|
|
2018-10-05 15:51:33 +08:00
|
|
|
|
Public ReadOnly ConnectTime As Date = Now
|
|
|
|
|
|
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Sub New(Socket As StateObject)
|
|
|
|
|
|
Me.ChunkBuffer = Socket.ChunkBuffer
|
|
|
|
|
|
Me.readBuffer = Socket.readBuffer
|
|
|
|
|
|
Me.workSocket = Socket.workSocket
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' DO_NOTHING
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="ar"></param>
|
|
|
|
|
|
Public Sub ReadCallback(ar As IAsyncResult)
|
|
|
|
|
|
' DO_NOTHING
|
|
|
|
|
|
End Sub 'ReadCallback
|
|
|
|
|
|
|
2018-10-05 20:42:01 +08:00
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Server send message to user client.
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="request"></param>
|
|
|
|
|
|
Public Sub PushMessage(request As RequestStream)
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Dim byteData As Byte() = request.Serialize
|
|
|
|
|
|
Try
|
|
|
|
|
|
Call Me.workSocket.Send(byteData, byteData.Length, SocketFlags.None)
|
|
|
|
|
|
Catch ex As Exception
|
|
|
|
|
|
Call ForceCloseHandle(Me)
|
|
|
|
|
|
End Try
|
|
|
|
|
|
End Sub
|
2018-10-06 16:14:58 +08:00
|
|
|
|
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Public Sub PushMessage(message As String)
|
|
|
|
|
|
Call PushMessage(New RequestStream(message))
|
|
|
|
|
|
End Sub
|
2018-08-02 20:14:48 +08:00
|
|
|
|
End Class
|
|
|
|
|
|
End Namespace
|