[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

pSm

10/31/2004 9:33:00 PM

Hi,
I was trying to write a basic chat client/server. I used remoting for this.
The server type uses a shared property message to keep track of the last sent
message. All the clients poll the server every 10ms to see if a new message
is arrived.

The server type is singleton. My guess was since the object is singleton and
message is shared, the last mesage posted by anyone would be visible to
anybody else.

For example, say A says 'Hi' . When B polls for the message, he should see
the 'Hi'. But what I see is, every client is seeing only the message that he
has posted and nothing else. So, if A says 'Hi' and B says 'Bye', A only sees
'Hi' and B only sees 'Bye'. Can anyone help me understand what's wrong ?

Second question is, after I saw that this was happening, I tried finding out
if the object is getting destroyed. So I put in a finalizer and some logs in
it. I see the finalizer run after every call from the client.Why is this so ?
8 Answers

Sam Santiago

10/31/2004 10:45:00 PM

0

Here's a remoting Chat example that uses events to accomplish what you want.
Also, if you are seeing the finalizer run each time you might have defined a
SingleCall SAO vs. a Singleton SAO. Check out this example for more info:

http://support.microsoft.com/default.aspx?scid=kb;en...

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"pSm" <pSm@discussions.microsoft.com> wrote in message
news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> Hi,
> I was trying to write a basic chat client/server. I used remoting for
this.
> The server type uses a shared property message to keep track of the last
sent
> message. All the clients poll the server every 10ms to see if a new
message
> is arrived.
>
> The server type is singleton. My guess was since the object is singleton
and
> message is shared, the last mesage posted by anyone would be visible to
> anybody else.
>
> For example, say A says 'Hi' . When B polls for the message, he should see
> the 'Hi'. But what I see is, every client is seeing only the message that
he
> has posted and nothing else. So, if A says 'Hi' and B says 'Bye', A only
sees
> 'Hi' and B only sees 'Bye'. Can anyone help me understand what's wrong ?
>
> Second question is, after I saw that this was happening, I tried finding
out
> if the object is getting destroyed. So I put in a finalizer and some logs
in
> it. I see the finalizer run after every call from the client.Why is this
so ?


pSm

11/1/2004 8:45:00 PM

0

Hi Sam,
Thanks for the post , but I am not really looking on how to implement
the chat program, but understanding/clearing my remoting concepts.

To re-iterate, I would like to know if my understanding that if the object
is singleton, and the message property is shared, every user would have
access to the same message value, is correct or not ?

Thanks,


"Sam Santiago" wrote:

> Here's a remoting Chat example that uses events to accomplish what you want.
> Also, if you are seeing the finalizer run each time you might have defined a
> SingleCall SAO vs. a Singleton SAO. Check out this example for more info:
>
> http://support.microsoft.com/default.aspx?scid=kb;en...
>
> Thanks,
>
> Sam
>
> --
> _______________________________
> Sam Santiago
> ssantiago@n0spam-SoftiTechture.com
> http://www.SoftiTe...
> _______________________________
> "pSm" <pSm@discussions.microsoft.com> wrote in message
> news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> > Hi,
> > I was trying to write a basic chat client/server. I used remoting for
> this.
> > The server type uses a shared property message to keep track of the last
> sent
> > message. All the clients poll the server every 10ms to see if a new
> message
> > is arrived.
> >
> > The server type is singleton. My guess was since the object is singleton
> and
> > message is shared, the last mesage posted by anyone would be visible to
> > anybody else.
> >
> > For example, say A says 'Hi' . When B polls for the message, he should see
> > the 'Hi'. But what I see is, every client is seeing only the message that
> he
> > has posted and nothing else. So, if A says 'Hi' and B says 'Bye', A only
> sees
> > 'Hi' and B only sees 'Bye'. Can anyone help me understand what's wrong ?
> >
> > Second question is, after I saw that this was happening, I tried finding
> out
> > if the object is getting destroyed. So I put in a finalizer and some logs
> in
> > it. I see the finalizer run after every call from the client.Why is this
> so ?
>
>
>

Ken Kolda

11/1/2004 8:54:00 PM

0

If the class is exposed as a singleton, the Message value should be shared
across all clients. The fact that you're seeing the object destroyed after
each call from a client implies this is SingleCall instead of Singleton
(although even then I wouldn't expect the finalizer to run right away unless
your forcing garbage collection). You want to post some code if you still
have issues.

Ken


"pSm" <pSm@discussions.microsoft.com> wrote in message
news:B31F2E03-2A5C-4E32-B9EC-FC7EB29E84D4@microsoft.com...
> Hi Sam,
> Thanks for the post , but I am not really looking on how to
implement
> the chat program, but understanding/clearing my remoting concepts.
>
> To re-iterate, I would like to know if my understanding that if the object
> is singleton, and the message property is shared, every user would have
> access to the same message value, is correct or not ?
>
> Thanks,
>
>
> "Sam Santiago" wrote:
>
> > Here's a remoting Chat example that uses events to accomplish what you
want.
> > Also, if you are seeing the finalizer run each time you might have
defined a
> > SingleCall SAO vs. a Singleton SAO. Check out this example for more
info:
> >
> > http://support.microsoft.com/default.aspx?scid=kb;en...
> >
> > Thanks,
> >
> > Sam
> >
> > --
> > _______________________________
> > Sam Santiago
> > ssantiago@n0spam-SoftiTechture.com
> > http://www.SoftiTe...
> > _______________________________
> > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> > > Hi,
> > > I was trying to write a basic chat client/server. I used remoting for
> > this.
> > > The server type uses a shared property message to keep track of the
last
> > sent
> > > message. All the clients poll the server every 10ms to see if a new
> > message
> > > is arrived.
> > >
> > > The server type is singleton. My guess was since the object is
singleton
> > and
> > > message is shared, the last mesage posted by anyone would be visible
to
> > > anybody else.
> > >
> > > For example, say A says 'Hi' . When B polls for the message, he should
see
> > > the 'Hi'. But what I see is, every client is seeing only the message
that
> > he
> > > has posted and nothing else. So, if A says 'Hi' and B says 'Bye', A
only
> > sees
> > > 'Hi' and B only sees 'Bye'. Can anyone help me understand what's wrong
?
> > >
> > > Second question is, after I saw that this was happening, I tried
finding
> > out
> > > if the object is getting destroyed. So I put in a finalizer and some
logs
> > in
> > > it. I see the finalizer run after every call from the client.Why is
this
> > so ?
> >
> >
> >


pSm

11/1/2004 9:19:00 PM

0

Ken,
Here's the server 'Type' --
--------------------------------------------------------------------------------------------
Imports System.Diagnostics
Public Class clsRemoteType
Inherits MarshalByRefObject

Private arrIDs(10) As String
Private Shared lastid As String

Private Shared message As String
Private count As Integer = 0
Public evt As New System.Diagnostics.EventLog("RemoteLog.txt")

Public Sub clsRemoteType()

evt.WriteEntry("APP", "Remote Type Created")
End Sub

Protected Overrides Sub finalize()
evt.WriteEntry("APP", "Remote Type Destroyed" + CStr(DateTime.Now))
End Sub

Public Sub send(ByVal id As String, ByVal msg As String)
Dim i As Integer
Dim blnFound As Boolean
For i = 0 To count
If (arrIDs(i) = id) Then
'Found - Already present no need to add
blnFound = True
Exit For
End If
Next

If (Not blnFound) Then
arrIDs(count) = id
count = count + 1
End If
lastid = id
message = msg

evt.WriteEntry("APP", "Message written -" + message +
CStr(DateTime.Now))
End Sub

Public Function receive() As String
Return (lastid + " : " + message)
End Function
End Clas
--------------------------------------------------------------------------------------------
The Host -->

Imports System
Imports System.Runtime.Remoting
Module Module1

Sub Main()
Try
RemotingConfiguration.Configure("../RemotingHost.exe.config")
Console.Write("Waiting for Connections to arrive --")

Console.ReadLine()

Catch ex As Exception
Console.Write("Exception Occured..")
End Try
End Sub

End Module

-------------------------------------------------------------------------------------------

The Server 'Config'

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="Singleton"
type="clsRemoteType, RemoteType.clsRemoteType"
objectUri="RemoteTypeURI.rem"
/>
</service>
<channels>
<channel ref="http" port="8989"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>

----------------------------------------------------------------------------------------------
The client -->

Code when a message is sent :

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSend.Click
Dim obj As New RemoteType.clsRemoteType
obj.send("ABC", txtMsg.Text)
End Sub

Code that polls ( a timer is used)

Private Sub tmPollMsg_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmPollMsg.Tick
Dim obj As New RemoteType.clsRemoteType
Dim str As String
str = obj.receive()
If Trim(str) <> ":" And lastmessage <> str Then
lblMsg.Text = lblMsg.Text + str + vbCrLf
lastmessage = str
End If
End Su
------------------------------------------------------------------------------------------
Client Config -->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown
type="clsRemoteType, RemoteType.clsRemoteType"
url="http://FLL020361:8989/RemoteTypeURI.rem"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>

---------------------------***************-------------------------------------

Thanks


"Ken Kolda" wrote:

> If the class is exposed as a singleton, the Message value should be shared
> across all clients. The fact that you're seeing the object destroyed after
> each call from a client implies this is SingleCall instead of Singleton
> (although even then I wouldn't expect the finalizer to run right away unless
> your forcing garbage collection). You want to post some code if you still
> have issues.
>
> Ken
>
>
> "pSm" <pSm@discussions.microsoft.com> wrote in message
> news:B31F2E03-2A5C-4E32-B9EC-FC7EB29E84D4@microsoft.com...
> > Hi Sam,
> > Thanks for the post , but I am not really looking on how to
> implement
> > the chat program, but understanding/clearing my remoting concepts.
> >
> > To re-iterate, I would like to know if my understanding that if the object
> > is singleton, and the message property is shared, every user would have
> > access to the same message value, is correct or not ?
> >
> > Thanks,
> >
> >
> > "Sam Santiago" wrote:
> >
> > > Here's a remoting Chat example that uses events to accomplish what you
> want.
> > > Also, if you are seeing the finalizer run each time you might have
> defined a
> > > SingleCall SAO vs. a Singleton SAO. Check out this example for more
> info:
> > >
> > > http://support.microsoft.com/default.aspx?scid=kb;en...
> > >
> > > Thanks,
> > >
> > > Sam
> > >
> > > --
> > > _______________________________
> > > Sam Santiago
> > > ssantiago@n0spam-SoftiTechture.com
> > > http://www.SoftiTe...
> > > _______________________________
> > > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > > news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> > > > Hi,
> > > > I was trying to write a basic chat client/server. I used remoting for
> > > this.
> > > > The server type uses a shared property message to keep track of the
> last
> > > sent
> > > > message. All the clients poll the server every 10ms to see if a new
> > > message
> > > > is arrived.
> > > >
> > > > The server type is singleton. My guess was since the object is
> singleton
> > > and
> > > > message is shared, the last mesage posted by anyone would be visible
> to
> > > > anybody else.
> > > >
> > > > For example, say A says 'Hi' . When B polls for the message, he should
> see
> > > > the 'Hi'. But what I see is, every client is seeing only the message
> that
> > > he
> > > > has posted and nothing else. So, if A says 'Hi' and B says 'Bye', A
> only
> > > sees
> > > > 'Hi' and B only sees 'Bye'. Can anyone help me understand what's wrong
> ?
> > > >
> > > > Second question is, after I saw that this was happening, I tried
> finding
> > > out
> > > > if the object is getting destroyed. So I put in a finalizer and some
> logs
> > > in
> > > > it. I see the finalizer run after every call from the client.Why is
> this
> > > so ?
> > >
> > >
> > >
>
>
>

Ken Kolda

11/1/2004 10:59:00 PM

0

The declaration of the <wellknown> type in your client and server config
files are wrong. The format of the type attribute is:

<wellknown type="Namespace.ClassName, AssemblyName" ... />

So, yours should look like:

<wellknown type="RemoteType.clsRemoteType, RemoteType" ... />

Ken


"pSm" <pSm@discussions.microsoft.com> wrote in message
news:7DF86AC8-663D-4AAE-8A45-68A2BF8DE4B6@microsoft.com...
> Ken,
> Here's the server 'Type' -->
> --------------------------------------------------------------------------
------------------
> Imports System.Diagnostics
> Public Class clsRemoteType
> Inherits MarshalByRefObject
>
> Private arrIDs(10) As String
> Private Shared lastid As String
>
> Private Shared message As String
> Private count As Integer = 0
> Public evt As New System.Diagnostics.EventLog("RemoteLog.txt")
>
> Public Sub clsRemoteType()
>
> evt.WriteEntry("APP", "Remote Type Created")
> End Sub
>
> Protected Overrides Sub finalize()
> evt.WriteEntry("APP", "Remote Type Destroyed" +
CStr(DateTime.Now))
> End Sub
>
> Public Sub send(ByVal id As String, ByVal msg As String)
> Dim i As Integer
> Dim blnFound As Boolean
> For i = 0 To count
> If (arrIDs(i) = id) Then
> 'Found - Already present no need to add
> blnFound = True
> Exit For
> End If
> Next
>
> If (Not blnFound) Then
> arrIDs(count) = id
> count = count + 1
> End If
> lastid = id
> message = msg
>
> evt.WriteEntry("APP", "Message written -" + message +
> CStr(DateTime.Now))
> End Sub
>
> Public Function receive() As String
> Return (lastid + " : " + message)
> End Function
> End Class
> --------------------------------------------------------------------------
------------------
> The Host -->
>
> Imports System
> Imports System.Runtime.Remoting
> Module Module1
>
> Sub Main()
> Try
> RemotingConfiguration.Configure("../RemotingHost.exe.config")
> Console.Write("Waiting for Connections to arrive --")
>
> Console.ReadLine()
>
> Catch ex As Exception
> Console.Write("Exception Occured..")
> End Try
> End Sub
>
> End Module
>
> --------------------------------------------------------------------------
-----------------
>
> The Server 'Config'
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.runtime.remoting>
> <application>
> <service>
> <wellknown
> mode="Singleton"
> type="clsRemoteType, RemoteType.clsRemoteType"
> objectUri="RemoteTypeURI.rem"
> />
> </service>
> <channels>
> <channel ref="http" port="8989"/>
> </channels>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> --------------------------------------------------------------------------
--------------------
> The client -->
>
> Code when a message is sent :
>
> Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnSend.Click
> Dim obj As New RemoteType.clsRemoteType
> obj.send("ABC", txtMsg.Text)
> End Sub
>
> Code that polls ( a timer is used)
>
> Private Sub tmPollMsg_Tick(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles tmPollMsg.Tick
> Dim obj As New RemoteType.clsRemoteType
> Dim str As String
> str = obj.receive()
> If Trim(str) <> ":" And lastmessage <> str Then
> lblMsg.Text = lblMsg.Text + str + vbCrLf
> lastmessage = str
> End If
> End Sub
> --------------------------------------------------------------------------
----------------
> Client Config -->
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.runtime.remoting>
> <application>
> <client>
> <wellknown
> type="clsRemoteType, RemoteType.clsRemoteType"
> url="http://FLL020361:8989/RemoteTypeURI.rem"
> />
> </client>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> ---------------------------***************--------------------------------
-----
>
> Thanks
>
>
> "Ken Kolda" wrote:
>
> > If the class is exposed as a singleton, the Message value should be
shared
> > across all clients. The fact that you're seeing the object destroyed
after
> > each call from a client implies this is SingleCall instead of Singleton
> > (although even then I wouldn't expect the finalizer to run right away
unless
> > your forcing garbage collection). You want to post some code if you
still
> > have issues.
> >
> > Ken
> >
> >
> > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > news:B31F2E03-2A5C-4E32-B9EC-FC7EB29E84D4@microsoft.com...
> > > Hi Sam,
> > > Thanks for the post , but I am not really looking on how to
> > implement
> > > the chat program, but understanding/clearing my remoting concepts.
> > >
> > > To re-iterate, I would like to know if my understanding that if the
object
> > > is singleton, and the message property is shared, every user would
have
> > > access to the same message value, is correct or not ?
> > >
> > > Thanks,
> > >
> > >
> > > "Sam Santiago" wrote:
> > >
> > > > Here's a remoting Chat example that uses events to accomplish what
you
> > want.
> > > > Also, if you are seeing the finalizer run each time you might have
> > defined a
> > > > SingleCall SAO vs. a Singleton SAO. Check out this example for more
> > info:
> > > >
> > > > http://support.microsoft.com/default.aspx?scid=kb;en...
> > > >
> > > > Thanks,
> > > >
> > > > Sam
> > > >
> > > > --
> > > > _______________________________
> > > > Sam Santiago
> > > > ssantiago@n0spam-SoftiTechture.com
> > > > http://www.SoftiTe...
> > > > _______________________________
> > > > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > > > news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> > > > > Hi,
> > > > > I was trying to write a basic chat client/server. I used remoting
for
> > > > this.
> > > > > The server type uses a shared property message to keep track of
the
> > last
> > > > sent
> > > > > message. All the clients poll the server every 10ms to see if a
new
> > > > message
> > > > > is arrived.
> > > > >
> > > > > The server type is singleton. My guess was since the object is
> > singleton
> > > > and
> > > > > message is shared, the last mesage posted by anyone would be
visible
> > to
> > > > > anybody else.
> > > > >
> > > > > For example, say A says 'Hi' . When B polls for the message, he
should
> > see
> > > > > the 'Hi'. But what I see is, every client is seeing only the
message
> > that
> > > > he
> > > > > has posted and nothing else. So, if A says 'Hi' and B says 'Bye',
A
> > only
> > > > sees
> > > > > 'Hi' and B only sees 'Bye'. Can anyone help me understand what's
wrong
> > ?
> > > > >
> > > > > Second question is, after I saw that this was happening, I tried
> > finding
> > > > out
> > > > > if the object is getting destroyed. So I put in a finalizer and
some
> > logs
> > > > in
> > > > > it. I see the finalizer run after every call from the client.Why
is
> > this
> > > > so ?
> > > >
> > > >
> > > >
> >
> >
> >


Ken Kolda

11/1/2004 11:05:00 PM

0

By the way, I should also mention a couple of other issues:

1) Your code isn't thread-safe. You need to implement some locking on your
server to ensure no two clients are setting the message at the same time (or
attempting to receive the message while it's being set).

2) You have your lastid and message fields on the cldRemoteType as Shared. I
don't see any reason from the code you've provided why you would want these
fields as shared instead of instance fields. Using shared fields will just
increase the likelihood of modifying them elsewhere in a non-thread-safe
manner.

Ken


"pSm" <pSm@discussions.microsoft.com> wrote in message
news:7DF86AC8-663D-4AAE-8A45-68A2BF8DE4B6@microsoft.com...
> Ken,
> Here's the server 'Type' -->
> --------------------------------------------------------------------------
------------------
> Imports System.Diagnostics
> Public Class clsRemoteType
> Inherits MarshalByRefObject
>
> Private arrIDs(10) As String
> Private Shared lastid As String
>
> Private Shared message As String
> Private count As Integer = 0
> Public evt As New System.Diagnostics.EventLog("RemoteLog.txt")
>
> Public Sub clsRemoteType()
>
> evt.WriteEntry("APP", "Remote Type Created")
> End Sub
>
> Protected Overrides Sub finalize()
> evt.WriteEntry("APP", "Remote Type Destroyed" +
CStr(DateTime.Now))
> End Sub
>
> Public Sub send(ByVal id As String, ByVal msg As String)
> Dim i As Integer
> Dim blnFound As Boolean
> For i = 0 To count
> If (arrIDs(i) = id) Then
> 'Found - Already present no need to add
> blnFound = True
> Exit For
> End If
> Next
>
> If (Not blnFound) Then
> arrIDs(count) = id
> count = count + 1
> End If
> lastid = id
> message = msg
>
> evt.WriteEntry("APP", "Message written -" + message +
> CStr(DateTime.Now))
> End Sub
>
> Public Function receive() As String
> Return (lastid + " : " + message)
> End Function
> End Class
> --------------------------------------------------------------------------
------------------
> The Host -->
>
> Imports System
> Imports System.Runtime.Remoting
> Module Module1
>
> Sub Main()
> Try
> RemotingConfiguration.Configure("../RemotingHost.exe.config")
> Console.Write("Waiting for Connections to arrive --")
>
> Console.ReadLine()
>
> Catch ex As Exception
> Console.Write("Exception Occured..")
> End Try
> End Sub
>
> End Module
>
> --------------------------------------------------------------------------
-----------------
>
> The Server 'Config'
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.runtime.remoting>
> <application>
> <service>
> <wellknown
> mode="Singleton"
> type="clsRemoteType, RemoteType.clsRemoteType"
> objectUri="RemoteTypeURI.rem"
> />
> </service>
> <channels>
> <channel ref="http" port="8989"/>
> </channels>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> --------------------------------------------------------------------------
--------------------
> The client -->
>
> Code when a message is sent :
>
> Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnSend.Click
> Dim obj As New RemoteType.clsRemoteType
> obj.send("ABC", txtMsg.Text)
> End Sub
>
> Code that polls ( a timer is used)
>
> Private Sub tmPollMsg_Tick(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles tmPollMsg.Tick
> Dim obj As New RemoteType.clsRemoteType
> Dim str As String
> str = obj.receive()
> If Trim(str) <> ":" And lastmessage <> str Then
> lblMsg.Text = lblMsg.Text + str + vbCrLf
> lastmessage = str
> End If
> End Sub
> --------------------------------------------------------------------------
----------------
> Client Config -->
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.runtime.remoting>
> <application>
> <client>
> <wellknown
> type="clsRemoteType, RemoteType.clsRemoteType"
> url="http://FLL020361:8989/RemoteTypeURI.rem"
> />
> </client>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> ---------------------------***************--------------------------------
-----
>
> Thanks
>
>
> "Ken Kolda" wrote:
>
> > If the class is exposed as a singleton, the Message value should be
shared
> > across all clients. The fact that you're seeing the object destroyed
after
> > each call from a client implies this is SingleCall instead of Singleton
> > (although even then I wouldn't expect the finalizer to run right away
unless
> > your forcing garbage collection). You want to post some code if you
still
> > have issues.
> >
> > Ken
> >
> >
> > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > news:B31F2E03-2A5C-4E32-B9EC-FC7EB29E84D4@microsoft.com...
> > > Hi Sam,
> > > Thanks for the post , but I am not really looking on how to
> > implement
> > > the chat program, but understanding/clearing my remoting concepts.
> > >
> > > To re-iterate, I would like to know if my understanding that if the
object
> > > is singleton, and the message property is shared, every user would
have
> > > access to the same message value, is correct or not ?
> > >
> > > Thanks,
> > >
> > >
> > > "Sam Santiago" wrote:
> > >
> > > > Here's a remoting Chat example that uses events to accomplish what
you
> > want.
> > > > Also, if you are seeing the finalizer run each time you might have
> > defined a
> > > > SingleCall SAO vs. a Singleton SAO. Check out this example for more
> > info:
> > > >
> > > > http://support.microsoft.com/default.aspx?scid=kb;en...
> > > >
> > > > Thanks,
> > > >
> > > > Sam
> > > >
> > > > --
> > > > _______________________________
> > > > Sam Santiago
> > > > ssantiago@n0spam-SoftiTechture.com
> > > > http://www.SoftiTe...
> > > > _______________________________
> > > > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > > > news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> > > > > Hi,
> > > > > I was trying to write a basic chat client/server. I used remoting
for
> > > > this.
> > > > > The server type uses a shared property message to keep track of
the
> > last
> > > > sent
> > > > > message. All the clients poll the server every 10ms to see if a
new
> > > > message
> > > > > is arrived.
> > > > >
> > > > > The server type is singleton. My guess was since the object is
> > singleton
> > > > and
> > > > > message is shared, the last mesage posted by anyone would be
visible
> > to
> > > > > anybody else.
> > > > >
> > > > > For example, say A says 'Hi' . When B polls for the message, he
should
> > see
> > > > > the 'Hi'. But what I see is, every client is seeing only the
message
> > that
> > > > he
> > > > > has posted and nothing else. So, if A says 'Hi' and B says 'Bye',
A
> > only
> > > > sees
> > > > > 'Hi' and B only sees 'Bye'. Can anyone help me understand what's
wrong
> > ?
> > > > >
> > > > > Second question is, after I saw that this was happening, I tried
> > finding
> > > > out
> > > > > if the object is getting destroyed. So I put in a finalizer and
some
> > logs
> > > > in
> > > > > it. I see the finalizer run after every call from the client.Why
is
> > this
> > > > so ?
> > > >
> > > >
> > > >
> >
> >
> >


pSm

11/2/2004 1:00:00 AM

0

Ken,
I did the changes to the config file and made message and ids as instance
fields. But I continue to have the same problem,i.e., message from one client
is not being shown to another client.

What is wrong ?
-pSm

"Ken Kolda" wrote:

> By the way, I should also mention a couple of other issues:
>
> 1) Your code isn't thread-safe. You need to implement some locking on your
> server to ensure no two clients are setting the message at the same time (or
> attempting to receive the message while it's being set).
>
> 2) You have your lastid and message fields on the cldRemoteType as Shared. I
> don't see any reason from the code you've provided why you would want these
> fields as shared instead of instance fields. Using shared fields will just
> increase the likelihood of modifying them elsewhere in a non-thread-safe
> manner.
>
> Ken
>
>
> "pSm" <pSm@discussions.microsoft.com> wrote in message
> news:7DF86AC8-663D-4AAE-8A45-68A2BF8DE4B6@microsoft.com...
> > Ken,
> > Here's the server 'Type' -->
> > --------------------------------------------------------------------------
> ------------------
> > Imports System.Diagnostics
> > Public Class clsRemoteType
> > Inherits MarshalByRefObject
> >
> > Private arrIDs(10) As String
> > Private Shared lastid As String
> >
> > Private Shared message As String
> > Private count As Integer = 0
> > Public evt As New System.Diagnostics.EventLog("RemoteLog.txt")
> >
> > Public Sub clsRemoteType()
> >
> > evt.WriteEntry("APP", "Remote Type Created")
> > End Sub
> >
> > Protected Overrides Sub finalize()
> > evt.WriteEntry("APP", "Remote Type Destroyed" +
> CStr(DateTime.Now))
> > End Sub
> >
> > Public Sub send(ByVal id As String, ByVal msg As String)
> > Dim i As Integer
> > Dim blnFound As Boolean
> > For i = 0 To count
> > If (arrIDs(i) = id) Then
> > 'Found - Already present no need to add
> > blnFound = True
> > Exit For
> > End If
> > Next
> >
> > If (Not blnFound) Then
> > arrIDs(count) = id
> > count = count + 1
> > End If
> > lastid = id
> > message = msg
> >
> > evt.WriteEntry("APP", "Message written -" + message +
> > CStr(DateTime.Now))
> > End Sub
> >
> > Public Function receive() As String
> > Return (lastid + " : " + message)
> > End Function
> > End Class
> > --------------------------------------------------------------------------
> ------------------
> > The Host -->
> >
> > Imports System
> > Imports System.Runtime.Remoting
> > Module Module1
> >
> > Sub Main()
> > Try
> > RemotingConfiguration.Configure("../RemotingHost.exe.config")
> > Console.Write("Waiting for Connections to arrive --")
> >
> > Console.ReadLine()
> >
> > Catch ex As Exception
> > Console.Write("Exception Occured..")
> > End Try
> > End Sub
> >
> > End Module
> >
> > --------------------------------------------------------------------------
> -----------------
> >
> > The Server 'Config'
> >
> > <?xml version="1.0" encoding="utf-8" ?>
> > <configuration>
> > <system.runtime.remoting>
> > <application>
> > <service>
> > <wellknown
> > mode="Singleton"
> > type="clsRemoteType, RemoteType.clsRemoteType"
> > objectUri="RemoteTypeURI.rem"
> > />
> > </service>
> > <channels>
> > <channel ref="http" port="8989"/>
> > </channels>
> > </application>
> > </system.runtime.remoting>
> > </configuration>
> >
> > --------------------------------------------------------------------------
> --------------------
> > The client -->
> >
> > Code when a message is sent :
> >
> > Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles btnSend.Click
> > Dim obj As New RemoteType.clsRemoteType
> > obj.send("ABC", txtMsg.Text)
> > End Sub
> >
> > Code that polls ( a timer is used)
> >
> > Private Sub tmPollMsg_Tick(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles tmPollMsg.Tick
> > Dim obj As New RemoteType.clsRemoteType
> > Dim str As String
> > str = obj.receive()
> > If Trim(str) <> ":" And lastmessage <> str Then
> > lblMsg.Text = lblMsg.Text + str + vbCrLf
> > lastmessage = str
> > End If
> > End Sub
> > --------------------------------------------------------------------------
> ----------------
> > Client Config -->
> > <?xml version="1.0" encoding="utf-8" ?>
> > <configuration>
> > <system.runtime.remoting>
> > <application>
> > <client>
> > <wellknown
> > type="clsRemoteType, RemoteType.clsRemoteType"
> > url="http://FLL020361:8989/RemoteTypeURI.rem"
> > />
> > </client>
> > </application>
> > </system.runtime.remoting>
> > </configuration>
> >
> > ---------------------------***************--------------------------------
> -----
> >
> > Thanks
> >
> >
> > "Ken Kolda" wrote:
> >
> > > If the class is exposed as a singleton, the Message value should be
> shared
> > > across all clients. The fact that you're seeing the object destroyed
> after
> > > each call from a client implies this is SingleCall instead of Singleton
> > > (although even then I wouldn't expect the finalizer to run right away
> unless
> > > your forcing garbage collection). You want to post some code if you
> still
> > > have issues.
> > >
> > > Ken
> > >
> > >
> > > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > > news:B31F2E03-2A5C-4E32-B9EC-FC7EB29E84D4@microsoft.com...
> > > > Hi Sam,
> > > > Thanks for the post , but I am not really looking on how to
> > > implement
> > > > the chat program, but understanding/clearing my remoting concepts.
> > > >
> > > > To re-iterate, I would like to know if my understanding that if the
> object
> > > > is singleton, and the message property is shared, every user would
> have
> > > > access to the same message value, is correct or not ?
> > > >
> > > > Thanks,
> > > >
> > > >
> > > > "Sam Santiago" wrote:
> > > >
> > > > > Here's a remoting Chat example that uses events to accomplish what
> you
> > > want.
> > > > > Also, if you are seeing the finalizer run each time you might have
> > > defined a
> > > > > SingleCall SAO vs. a Singleton SAO. Check out this example for more
> > > info:
> > > > >
> > > > > http://support.microsoft.com/default.aspx?scid=kb;en...
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Sam
> > > > >
> > > > > --
> > > > > _______________________________
> > > > > Sam Santiago
> > > > > ssantiago@n0spam-SoftiTechture.com
> > > > > http://www.SoftiTe...
> > > > > _______________________________
> > > > > "pSm" <pSm@discussions.microsoft.com> wrote in message
> > > > > news:1DD1BB89-DC6E-422A-A8E7-C0BB2F05A273@microsoft.com...
> > > > > > Hi,
> > > > > > I was trying to write a basic chat client/server. I used remoting
> for
> > > > > this.
> > > > > > The server type uses a shared property message to keep track of
> the
> > > last
> > > > > sent
> > > > > > message. All the clients poll the server every 10ms to see if a
> new
> > > > > message
> > > > > > is arrived.
> > > > > >
> > > > > > The server type is singleton. My guess was since the object is
> > > singleton
> > > > > and
> > > > > > message is shared, the last mesage posted by anyone would be
> visible
> > > to
> > > > > > anybody else.
> > > > > >
> > > > > > For example, say A says 'Hi' . When B polls for the message, he
> should
> > > see
> > > > > > the 'Hi'. But what I see is, every client is seeing only the
> message
> > > that
> > > > > he
> > > > > > has posted and nothing else. So, if A says 'Hi' and B says 'Bye',
> A
> > > only
> > > > > sees
> > > > > > 'Hi' and B only sees 'Bye'. Can anyone help me understand what's
> wrong
> > > ?
> > > > > >
> > > > > > Second question is, after I saw that this was happening, I tried
> > > finding
> > > > > out
> > > > > > if the object is getting destroyed. So I put in a finalizer and
> some
> > > logs
> > > > > in
> > > > > > it. I see the finalizer run after every call from the client.Why
> is
> > > this
> > > > > so ?
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>
>

pSm

11/4/2004 1:33:00 AM

0

Hi Ken,
I was so frustated by this .. I deleted the whole client project and
re-wrote it and to my surprise, it is working perfectly. Though I hate such a
situation where I don't know what happened, I guess we all have to live with
it sometimes.

Really Appreciate your help. Thanks !
pSm

"pSm" wrote:

> Hi,
> I was trying to write a basic chat client/server. I used remoting for this.
> The server type uses a shared property message to keep track of the last sent
> message. All the clients poll the server every 10ms to see if a new message
> is arrived.
>
> The server type is singleton. My guess was since the object is singleton and
> message is shared, the last mesage posted by anyone would be visible to
> anybody else.
>
> For example, say A says 'Hi' . When B polls for the message, he should see
> the 'Hi'. But what I see is, every client is seeing only the message that he
> has posted and nothing else. So, if A says 'Hi' and B says 'Bye', A only sees
> 'Hi' and B only sees 'Bye'. Can anyone help me understand what's wrong ?
>
> Second question is, after I saw that this was happening, I tried finding out
> if the object is getting destroyed. So I put in a finalizer and some logs in
> it. I see the finalizer run after every call from the client.Why is this so ?