Click here to Skip to main content
15,895,256 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to get , what of day NO. between 2 date by days? Pin
Ahmed El-Badry19-May-08 21:15
Ahmed El-Badry19-May-08 21:15 
GeneralRe: How to get , what of day NO. between 2 date by days? Pin
Ahmed El-Badry19-May-08 21:13
Ahmed El-Badry19-May-08 21:13 
QuestionHow would you break up a textarea into 800 word pages? Pin
CCMint18-May-08 11:30
CCMint18-May-08 11:30 
AnswerRe: How would you break up a textarea into 800 word pages? Pin
Christian Graus18-May-08 12:07
protectorChristian Graus18-May-08 12:07 
Questionupdate problem Pin
asha_s18-May-08 7:48
asha_s18-May-08 7:48 
AnswerRe: update problem Pin
Christian Graus18-May-08 11:45
protectorChristian Graus18-May-08 11:45 
GeneralRe: update problem Pin
asha_s18-May-08 22:38
asha_s18-May-08 22:38 
Question.NET Remoting (please help ...) [modified] Pin
farzadmf18-May-08 4:15
farzadmf18-May-08 4:15 
D'Oh! | :doh:
Hi to all,

PLEASE PLEASE PLEASE HELP ME, SORRY IF MY MESSAGE IS SO LONG, BUT I COULDN'T FIND A WAY TO AT LEAST UPLOAD MY CODE FILES SO I HAD TO INSERT ALL THE CODE HERE, BUT PLEASE HELP, I'M REALLYYYYYYYYY STOCKED AND I WILL BE VERY VERY VERYYYYYYYY THANKFUL IF SOMEONE HELPS ME ............

Frown | :( Frown | :( Frown | :( Frown | :( Frown | :( Frown | :( Frown | :( Frown | :(

I am reading the Microsoft's book for exam 70-310 & 70-320 and I have a problem in Chapter 4's lab which I didn't manage to solve ... please help me ...
It's a simple chat application using .NET remoting:
We have a ChatCoordinator class and a SubmitEventArgs class (saved in a file named: CChatCoordinator.vb) with the following code:

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

Imports System
Imports System.Runtime.Remoting
Imports System.Collections

Serializable()> _
Public Class SubmitEventArgs
    Inherits EventArgs

    Private message As String = Nothing
    Private userName As String = Nothing

    Public Sub New(ByVal contribution As String, _
        ByVal contributor As String)
        Me.message = contribution
        Me.userName = contributor
    End Sub ' New

    Public ReadOnly Property Contribution() As String
        Get
            Return message
        End Get
    End Property

    Public ReadOnly Property Contributor() As String
        Get
            Return userName
        End Get
    End Property
End Class ' SubmitEventArgs

Public Delegate Sub SubmissionEventHandler(ByVal sender As Object, _
    ByVal submitArgs As SubmitEventArgs)

Public Class ChatCoordinator
    Inherits MarshalByRefObject
    Public Sub New()
        Console.WriteLine("ChatCoordinator created. Instance: " & _
            Me.GetHashCode().ToString())
    End Sub ' New

    Public Overrides Function InitializeLifetimeService() As Object
        Return Nothing
    End Function ' InitializeLifetimeService

    Public Event Submission As SubmissionEventHandler

    Public Sub Submit(ByVal contribution As String, _
        ByVal contributor As String)
        Console.WriteLine("{0} says: {1}.", _
            contributor, contribution)
        Dim e As New SubmitEventArgs(contribution, contributor)
        Console.WriteLine("Broadcasting...")
        RaiseEvent Submission(Me, e)
    End Sub ' Submit
End Class ' ChatCoordinator


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

We have a Server class (in a file named: CServer.vb):

Imports System
Imports System.Diagnostics
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels

Public Class Server
    Public Shared Sub Main()
        RemotingConfiguration.Configure("Central.config")
        Console.WriteLine("The host application is currently " & _
            "running. Press Enter to exit.")
        Console.ReadLine()
    End Sub ' Main
End Class ' Server


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

The Central.config file, which is used by the Server class for configuration is as follows (I had to delete the beginning "<" characters to avoid interception with HTML here):

configuration>
    system.runtime.remoting>
        application>
            service>
                wellknown
                    mode="Singleton"
                    type="ChatCoordinator, ChatCoordinator"
                    objectUri="Chat"
                />
            /service>
            channels>
                channel ref="http" port="8080" />
            /channels>
        /application>
    /system.runtime.remoting>
/configuration>


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

And finally, we have a ChatClient class (saved in a file named CChatClient.vb):

Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports Microsoft.VisualBasic

Public Class ChatClient
    Inherits MarshalByRefObject

    Public Overrides Function InitializeLifetimeService() As Object
        Return Nothing
    End Function

    Private userName As String = Nothing

    Public Sub New(ByVal [alias] As String)
        Me.userName = [alias]
    End Sub

    Public Sub Run()
        RemotingConfiguration.Configure("Client.config")
        Dim chatCenter As New ChatCoordinator
        AddHandler chatCenter.Submission, AddressOf _
            Me.SubmissionReceiver
        Dim userInput As String = ""
        While True
            Console.WriteLine("Press 0 (zero) and ENTER to Exit:")
            userInput = Console.ReadLine()
            If userInput = "0" Then Exit While
            chatCenter.Submit(userInput, userName)
        End While
        RemoveHandler chatCenter.Submission, AddressOf _
            Me.SubmissionReceiver
    End Sub

    Public Sub SubmissionReceiver(ByVal sender As Object, _
        ByVal args As SubmitEventArgs)
        If args.Contributor = userName Then
            Console.WriteLine("Your message was broadcast.")
        Else
            Console.WriteLine(args.Contributor & " says: " & _
                args.Contribution)
        End If
    End Sub ' SubmissionReceiver

    Public Shared Sub Main()
        Dim args() As String = Environment.GetCommandLineArgs()
        If args.Length <> 2 Then
            Console.WriteLine("You need to type an alias.")
            Return
        End If
        Dim client As New ChatClient(args(1))
        client.Run()
    End Sub ' Main
End Class ' ChatClient


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

And the Client.config used by the Client class (Again, beginning "<" characters here are deleted intentionally):

configuration>
    system.runtime.remoting>
        application>
            client>
                wellknown
                    type="ChatCoordinator, ChatCoordinator"
                    url="http://localhost:8080/Chat"
                />
            /client>
            channels>
                channel ref="http" port="0" />
            /channels>
        /application>
    /system.runtime.remoting>
/configuration>


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

I use the VB compiler at the Command Prompt to compile the codes:
vbc /t:library CChatCoordinator.vb<br />
vbc /r:CChatCoordinator.dll CServer.vb<br />
vbc /r:CChatCoordinator.dll CChatClient.vb


and then store CChatCoordinator.dll, Cserver.exe and Central.config in a folder named Server and store CChatCoordinator.dll, CChatClient.exe and Client.config in another folder named Client.

After that, I try to run the application:
Also it appears to me that running CChatClient.exe in the Command Prompt without running CServer.exe in another Command Prompt would generate an exception, the CChatClient.exe is executed without any errors.

Because of this, I think that the program doesn't interpret the ChatCoordinator class (in the CChatCoordinator.dll file) as a remotable object and it uses it's methods regardless of whether the CServer.exe is running or not.

Although when I run CChatClient.exe, my firewall tells me that this program wants to connect at a random port becuase of port="0" in the Client.config file, It appears to me that the Client class doesn't care what the Client.config file says; because I even tried to misspell some elements in Client.config but no error was generated.

And because of all the things that I said, when I open three diferent Command Prompt windows and type these:
1. CServer (in the Server directory)
2. CChatClient user1 (in the Client directory)
3. CChatClient user2 (in the Client directory)

and then I try to send messages from one use to the other, the messages only appear in its own user window not the other user.
For example, when I type "Hello" and press enter in user1's window, only the following appears in user1's window:

user1 says: hello.
Broadcasting...
Your message was broadcast.


and nothing appears in user2's window.

Are file names important here? For example, should the Server class be inside a file named Server.vb? Is it really important? I also tried to change the configuration file names to filename.exe.config but it also didn't solve the problem.
Frown | :( Frown | :(

Please help me, I searched the articles, read MSDN, and manipulated the code many many times, but I couldn't find the problem. Please help ......

modified on Monday, May 19, 2008 4:46 AM

Questionvb.net Pin
meuandme17-May-08 1:22
meuandme17-May-08 1:22 
AnswerRe: vb.net Pin
Dave Kreskowiak17-May-08 2:27
mveDave Kreskowiak17-May-08 2:27 
RantRe: vb.net Pin
Smithers-Jones17-May-08 11:30
Smithers-Jones17-May-08 11:30 
AnswerRe: vb.net Pin
Christian Graus17-May-08 12:39
protectorChristian Graus17-May-08 12:39 
QuestionMoving Character Glyphs Pin
Quecumber25616-May-08 8:16
Quecumber25616-May-08 8:16 
AnswerRe: Moving Character Glyphs Pin
Dave Kreskowiak17-May-08 2:23
mveDave Kreskowiak17-May-08 2:23 
GeneralRe: Moving Character Glyphs Pin
Quecumber25617-May-08 3:25
Quecumber25617-May-08 3:25 
QuestionHelp me in choosing the VB.Net Software Pin
avin200316-May-08 5:14
avin200316-May-08 5:14 
AnswerRe: Help me in choosing the VB.Net Software Pin
Thomas Stockwell16-May-08 10:38
professionalThomas Stockwell16-May-08 10:38 
GeneralRe: Help me in choosing the VB.Net Software Pin
avin200316-May-08 18:01
avin200316-May-08 18:01 
GeneralRe: Help me in choosing the VB.Net Software Pin
Christian Graus16-May-08 19:14
protectorChristian Graus16-May-08 19:14 
GeneralRe: Help me in choosing the VB.Net Software Pin
Thomas Stockwell17-May-08 3:55
professionalThomas Stockwell17-May-08 3:55 
GeneralRe: Help me in choosing the VB.Net Software Pin
avin200317-May-08 13:00
avin200317-May-08 13:00 
AnswerRe: Help me in choosing the VB.Net Software Pin
Christian Graus16-May-08 14:13
protectorChristian Graus16-May-08 14:13 
Answerduplicate move Pin
leckey16-May-08 15:34
leckey16-May-08 15:34 
Questionserial port Pin
Assaf8216-May-08 3:21
Assaf8216-May-08 3:21 
AnswerRe: serial port Pin
CPallini16-May-08 3:33
mveCPallini16-May-08 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.