More readable
- From: "Jonathan Boivin" <djon@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 20 Sep 2006 15:39:26 -0400
Imports System.Collections
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Remoting.Lifetime
Public Class Chatter
Inherits MarshalByRefObject
Private history As Queue = New Queue
Private Shared uniqueNumber As Integer = 0
Private _NbClients As Integer = 0
Private myUniqueLock As Object = New Object
Private myUniqueLock2 As Object = New Object
Private debugWriter As IO.StreamWriter 'For debug purpose, will be
removed
Public ReadOnly Property GetUniqueNumber() As Integer
Get
SyncLock (myUniqueLock)
uniqueNumber += 1
Return uniqueNumber
End SyncLock
End Get
End Property
Public ReadOnly Property NbClients() As Integer
Get
Return _NbClients
End Get
End Property
Public Event MessageEvent As MessageEventHandler
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Public Sub New()
debugWriter = New IO.StreamWriter("C:\test2.txt", True) 'For debug
purpose, will be removed
debugWriter.AutoFlush = True 'For debug purpose, will be removed
End Sub
<OneWay()> _
Public Sub Send(ByVal sender As String, ByVal message As String)
LogText(New String("-"c, 80))
LogText(sender & " said: " & message)
LogText(New String("-"c, 80))
Queue.Synchronized(history).Enqueue(String.Format("At {0} {1} said:
{2}", DateTime.Now, sender, message))
DoMessageEvent(sender, message)
End Sub
<OneWay()> _
Public Sub Connect()
SyncLock (myUniqueLock2)
_NbClients += 1
End SyncLock
LogText("# de clients connectés : " & NbClients)
End Sub
<OneWay()> _
Public Sub Disconnect()
SyncLock (myUniqueLock2)
_NbClients -= 1
End SyncLock
LogText("# de clients connectés : " & NbClients)
End Sub
Private Sub DoMessageEvent(ByVal sender As String, ByVal message As
String)
RaiseEvent MessageEvent(Me, New ChatEventArgs(sender, message))
End Sub
<OneWay()> _
Public Sub ShowHistory()
Dim O As Object
For Each O In history
DoMessageEvent("server-history", O.ToString())
Next
End Sub
Public Sub LogText(ByVal Log As String)
debugWriter.WriteLine(Log) 'For debug purpose, will be removed
Console.WriteLine(Log)
End Sub
Protected Overrides Sub Finalize()
debugWriter.Close() 'For debug purpose, will be removed
MyBase.Finalize()
End Sub
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: uO9qx1N3GHA.2096@xxxxxxxxxxxxxxxxxxxxxxx
Imports System.Collections
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Remoting.Lifetime
Public Class Chatter
Inherits MarshalByRefObject
Private history As Queue = New Queue
Private Shared uniqueNumber As Integer = 0
Private myUniqueLock As Object = New Object
Private debugWriter As IO.StreamWriter 'For debug purpose, will be removed
Public ReadOnly Property GetUniqueNumber() As Integer
Get
SyncLock (myUniqueLock)
uniqueNumber += 1
Return uniqueNumber
End SyncLock
End Get
End Property
Public Event MessageEvent As MessageEventHandler
Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function
Public Sub New()
debugWriter = New IO.StreamWriter("C:\test2.txt", True) 'For debug
purpose, will be removed
debugWriter.AutoFlush = True 'For debug purpose, will be removed
End Sub
<OneWay()> _
Public Sub Send(ByVal sender As String, ByVal message As String)
LogText(New String("-"c, 80))
LogText(sender & " said: " & message)
LogText(New String("-"c, 80))
Queue.Synchronized(history).Enqueue(String.Format("At {0} {1} said: {2}",
DateTime.Now, sender, message))
DoMessageEvent(sender, message)
End Sub
Private Sub DoMessageEvent(ByVal sender As String, ByVal message As
String)
RaiseEvent MessageEvent(Me, New ChatEventArgs(sender, message))
End Sub
<OneWay()> _
Public Sub ShowHistory()
Dim O As Object
For Each O In history
DoMessageEvent("server-history", O.ToString())
Next
End Sub
Public Sub LogText(ByVal Log As String)
debugWriter.WriteLine(Log) 'For debug purpose, will be removed
Console.WriteLine(Log)
End Sub
Protected Overrides Sub Finalize()
debugWriter.Close() 'For debug purpose, will be removed
MyBase.Finalize()
End Sub
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
- Chatter class
- From: Jonathan Boivin
- Remoting working 95% of the times (Expert question)
- Prev by Date: More Readable
- Next by Date: Re: File permissions and dynamic assembly loading
- Previous by thread: Chatter class
- Next by thread: Client class
- Index(es):
Relevant Pages
|