More Readable
- From: "Jonathan Boivin" <djon@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 20 Sep 2006 15:38:21 -0400
Imports System.Runtime.Remoting
Imports System.Security.Principal
Imports System.Runtime.Remoting.Lifetime
Imports Softconcepts.ApplicationBlocks.RadioPattern
Public Class Client
Inherits MarshalByRefObject
Implements IDisposable
Private FChatter As Chatter
Private Shared FClient As Client = Nothing
Private Shared ConstructorError As Boolean
Private unique As Integer = 0
Private Shared _WaitingTriggerNo As Integer = 0
Private Shared _WaitingAccepted As Boolean = False
Private myUniqueLock As Object = New Object
Private myUniqueLock2 As Object = New Object
Private myUniqueLock3 As Object = New Object
Private WaitingTriggerThread As Threading.Thread
Public Property WaitingTriggerNo() As Integer
Get
SyncLock (myUniqueLock)
Return _WaitingTriggerNo
End SyncLock
End Get
Set(ByVal value As Integer)
SyncLock (myUniqueLock)
_WaitingTriggerNo = value
End SyncLock
End Set
End Property
Public Property WaitingAccepted() As Boolean
Get
SyncLock (myUniqueLock)
Return _WaitingAccepted
End SyncLock
End Get
Set(ByVal value As Boolean)
SyncLock (myUniqueLock)
_WaitingAccepted = value
End SyncLock
End Set
End Property
Private Sub WaitingTriggerThreadSpin()
Dim TimeOutCount As Integer = 10000
Do While WaitingAccepted = False And TimeOutCount > 0
Instance.FChatter.LogText("Waiting " & WaitingTriggerNo & " by "
& Instance.unique)
Threading.Thread.Sleep(100)
TimeOutCount -= 1
Loop
End Sub
Private Sub New(Optional ByVal ConfigPath As String = "")
If ConfigPath = "" Then ConfigPath = "Clinica.exe.config"
Try
RemotingConfiguration.Configure(ConfigPath, False)
FChatter = New Chatter
AddHandler FChatter.MessageEvent, AddressOf OnMessageEvent
unique = FChatter.GetUniqueNumber
FChatter.Connect()
Catch
ConstructorError = True
End Try
End Sub
Public Shared ReadOnly Property Instance(Optional ByVal ConfigPath As
String = "") As Client
Get
If (FClient Is Nothing) Then
ConstructorError = False
FClient = New Client(ConfigPath)
End If
Return FClient
End Get
End Property
Public Sub Dispose() Implements System.IDisposable.Dispose
RemoveHandler FChatter.MessageEvent, AddressOf OnMessageEvent
End Sub
Public Shared Sub Shutdown()
Instance.FChatter.Disconnect()
Try
FClient.Dispose()
GC.SuppressFinalize(FClient)
Catch
End Try
End Sub
Public Shared Sub ShowHistory()
Instance.FChatter.ShowHistory()
If ConstructorError Then Instance.OnMessageEvent("client", New
ChatEventArgs("server", "Server not foundable"))
End Sub
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Public Shared Sub Send(ByVal sender As String, ByVal message As String)
Dim a As Client = Instance
Instance.FChatter.LogText("Sending message by " & Instance.unique &
" : " & sender & ":" & message)
Instance.FChatter.Send(sender, message)
Instance.FChatter.LogText("Message Sent by " & Instance.unique & " :
" & sender & ":" & message)
If ConstructorError Then Instance.OnMessageEvent("client", New
ChatEventArgs("server", "Server not foundable"))
End Sub
Public Sub OnMessageEvent(ByVal Sender As Object, ByVal e As
ChatEventArgs)
If e.Sender = "DB" Then
If e.Message.EndsWith("hello") = False Then
If e.Message = WaitingTriggerNo Then
WaitingAccepted = True
End If
End If
End If
Instance.FChatter.LogText("Message Received by " & Instance.unique &
" : " & e.Sender & ":" & e.Message & ":" & e.Message.EndsWith("hello") & ":"
& WaitingAccepted & ":" & WaitingTriggerNo)
If (Not IsSelf(e.Sender)) Then
REM Broadcaster.Broadcast(Environment.NewLine)
Broadcaster.Broadcast("{0} said: {1}", e.Sender, e.Message)
REM Broadcaster.Broadcast("chat>")
End If
End Sub
Private Function IsSelf(ByVal sender As String) As Boolean
#If DEBUG Then
Return False
#Else
Return sender = WindowsIdentity.GetCurrent().Name
#End If
End Function
Public Sub WaitForEndDB(ByVal NoTrigger As Integer)
Instance.FChatter.LogText("Entered WaitForEndDB by " &
Instance.unique)
WaitingTriggerThread = New Threading.Thread(AddressOf
WaitingTriggerThreadSpin)
WaitingTriggerNo = NoTrigger
WaitingAccepted = False
WaitingTriggerThread.Start()
WaitingTriggerThread.Join()
Instance.FChatter.LogText("Quitting WaitForEndDB by " &
Instance.unique)
End Sub
Public Overrides Function GetHashCode() As Integer
Return unique
End Function
Public Overrides Function ToString() As String
Return MyBase.ToString() & ":" & WindowsIdentity.GetCurrent().Name
End Function
End Class
--
Au plaisir,
Jonathan Boivin
---
Courriel : jonathanboivin@xxxxxxxxx
CyberInternautes : http://www.cints.net
Téléphone : 514-779-1129
"Jonathan Boivin" <djon@xxxxxxxxxxxxxxxxxxxx> a écrit dans le message de
news: O9f4D2N3GHA.4648@xxxxxxxxxxxxxxxxxxxxxxx
Imports System.Runtime.Remoting
Imports System.Security.Principal
Imports System.Runtime.Remoting.Lifetime
Imports Softconcepts.ApplicationBlocks.RadioPattern
Public Class Client
Inherits MarshalByRefObject
Implements IDisposable
Private FChatter As Chatter
Private Shared FClient As Client = Nothing
Private Shared ConstructorError As Boolean
Private unique As Integer = 0
Private Shared _WaitingTriggerNo As Integer = 0
Private Shared _WaitingAccepted As Boolean = False
Private myUniqueLock As Object = New Object
Private myUniqueLock2 As Object = New Object
Private WaitingTriggerThread As Threading.Thread
Public Property WaitingTriggerNo() As Integer
Get
SyncLock (myUniqueLock)
Return _WaitingTriggerNo
End SyncLock
End Get
Set(ByVal value As Integer)
SyncLock (myUniqueLock)
_WaitingTriggerNo = value
End SyncLock
End Set
End Property
Public Property WaitingAccepted() As Boolean
Get
SyncLock (myUniqueLock)
Return _WaitingAccepted
End SyncLock
End Get
Set(ByVal value As Boolean)
SyncLock (myUniqueLock)
_WaitingAccepted = value
End SyncLock
End Set
End Property
Private Sub WaitingTriggerThreadSpin()
Dim TimeOutCount As Integer = 10000
Do While WaitingAccepted = False And TimeOutCount > 0
Instance.FChatter.LogText("Waiting " & WaitingTriggerNo & " by " &
Instance.unique)
Threading.Thread.Sleep(100)
TimeOutCount -= 1
Loop
End Sub
Private Sub New(Optional ByVal ConfigPath As String = "")
If ConfigPath = "" Then ConfigPath = "Clinica.exe.config"
Try
RemotingConfiguration.Configure(ConfigPath, False)
FChatter = New Chatter
AddHandler FChatter.MessageEvent, AddressOf OnMessageEvent
unique = FChatter.GetUniqueNumber
Catch
ConstructorError = True
End Try
End Sub
Public Shared ReadOnly Property Instance(Optional ByVal ConfigPath As
String = "") As Client
Get
If (FClient Is Nothing) Then
ConstructorError = False
FClient = New Client(ConfigPath)
End If
Return FClient
End Get
End Property
Public Sub Dispose() Implements System.IDisposable.Dispose
RemoveHandler FChatter.MessageEvent, AddressOf OnMessageEvent
End Sub
Public Shared Sub Shutdown()
Try
FClient.Dispose()
GC.SuppressFinalize(FClient)
Catch
End Try
End Sub
Public Shared Sub ShowHistory()
Instance.FChatter.ShowHistory()
If ConstructorError Then Instance.OnMessageEvent("client", New
ChatEventArgs("server", "Server not foundable"))
End Sub
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Public Shared Sub Send(ByVal sender As String, ByVal message As String)
Dim a As Client = Instance
Instance.FChatter.LogText("Sending message by " & Instance.unique & " : "
& sender & ":" & message)
Instance.FChatter.Send(sender, message)
Instance.FChatter.LogText("Message Sent by " & Instance.unique & " : " &
sender & ":" & message)
If ConstructorError Then Instance.OnMessageEvent("client", New
ChatEventArgs("server", "Server not foundable"))
End Sub
Public Sub OnMessageEvent(ByVal Sender As Object, ByVal e As
ChatEventArgs)
If e.Sender = "DB" Then
If e.Message.EndsWith("hello") = False Then
If e.Message = WaitingTriggerNo Then
WaitingAccepted = True
End If
End If
End If
Instance.FChatter.LogText("Message Received by " & Instance.unique & " : "
& e.Sender & ":" & e.Message & ":" & e.Message.EndsWith("hello") & ":" &
WaitingAccepted)
If (Not IsSelf(e.Sender)) Then
REM Broadcaster.Broadcast(Environment.NewLine)
Broadcaster.Broadcast("{0} said: {1}", e.Sender, e.Message)
REM Broadcaster.Broadcast("chat>")
End If
End Sub
Private Function IsSelf(ByVal sender As String) As Boolean
#If DEBUG Then
Return False
#Else
Return sender = WindowsIdentity.GetCurrent().Name
#End If
End Function
Public Sub WaitForEndDB(ByVal NoTrigger As Integer)
Instance.FChatter.LogText("Entered WaitForEndDB by " & Instance.unique)
WaitingTriggerThread = New Threading.Thread(AddressOf
WaitingTriggerThreadSpin)
WaitingTriggerNo = NoTrigger
WaitingAccepted = False
WaitingTriggerThread.Start()
WaitingTriggerThread.Join()
Instance.FChatter.LogText("Quitting WaitForEndDB by " & Instance.unique)
End Sub
Public Overrides Function GetHashCode() As Integer
Return unique
End Function
Public Overrides Function ToString() As String
Return MyBase.ToString() & ":" & WindowsIdentity.GetCurrent().Name
End Function
End Class
--
Au plaisir,
Jonathan Boivin
---
Courriel : jonathanboivin@xxxxxxxxx
CyberInternautes : http://www.cints.net
Téléphone : 514-779-1129
"Jonathan Boivin" <djon@xxxxxxxxxxxxxxxxxxxx> a écrit dans le message de
news: OkZUBzM3GHA.3364@xxxxxxxxxxxxxxxxxxxxxxx
Hi people !
I used a remoting chat already built using events and a singleton object
on the server.
The events work fine, but not the method calling each time to send a
message.
When I call the send method and when it bugs (i have trace on the client
& server side), I can see my client trace but not the server trace. Let
me explain you a little bit more what is really strange.
I have two types of client (my principal and the notifier). I am
currently talking about the notifier. This notifier is a little and
really simple app which is used to send a single message to my principal
clients via other sources (like the DB). The notifier sends at first a
hello message and then, the message to forward.
The problem is happening when the message to forward is being sent. Which
means here that the hello message was sent correctly, but not the other
one. Weird hey ?
I joined a debug trace file. Here is a little explanation about it :
- When you see 'by 1' it represents a message received or sent by my
principal client.
- When you see 'by #' which # is not 1, it represents a message sent by
the notifier program.
- The trace 'Sending message by' is located on the client side, which
after this you should see a line + SomeOne said: something + a line (the
important keyword here is 'said:') (this trace is located on the server
side).
- The trace 'Receiving message by' is located on the client side.
- There is multiple trys in this debug file, there all good except one. A
try starts by 'Entered WaitForEndDB by' and ends by 'Quitting
WaitForEndDB by'.
- Search for 'Waiting 849 by 1' to get to the BUGGING part. (the number
849 is resent, but this was done manually to debug my principal client).
Here you can see the trace of sending hello on client and server side,
but we only see the sending of the number on the client side and not
server.
- Search for 'Waiting 841 by 1' to get to a FUNCTIONAL part.
Thanks for looking at my problem and don't hesitate to ask other
questions if you don't understand something,
Jonathan Boivin
---
Courriel : jonathanboivin@xxxxxxxxx
CyberInternautes : http://www.cints.net
.
- References:
- Remoting working 95% of the times (Expert question)
- From: Jonathan Boivin
- Client class
- From: Jonathan Boivin
- Remoting working 95% of the times (Expert question)
- Prev by Date: Re: Requested Service Not Found
- Next by Date: More readable
- Previous by thread: Client class
- Next by thread: Server config file
- Index(es):
Relevant Pages
|