Tcp channel protocol violation

Eaglestorm26

New member
Joined
May 20, 2010
Messages
3
Programming Experience
1-3
Hello I am working on a simple Remoting example to get the basic understanding of it. However I am getting an error when creating the Remoteobject in the client that says "Tcp Channel protocol violation" was encountered. I was wondering what I have set up that would cause this below is the setup of my code.

'Code for the server page form.
VB.NET:
Imports System.Runtime.Remoting

Public Class HostForm
    Inherits System.Windows.Forms.Form
    Private Sub HostForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Start listening for client requests, according to the 
        'information specified in the configuration file.

        Try
            RemotingConfiguration.Configure("SimpleServer.exe.config")

        Catch ex As Exception
            Dim err As String
            err = ex.Message
            MessageBox.Show("Error :" & err)
        End Try
    End Sub
End Class

'Code for the client page form

VB.NET:
Imports System.Runtime.Remoting
Public Class ClientForm

    Private Sub ClientForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Configure the Client
        RemotingConfiguration.Configure("SimpleClient.exe.config", False)

        'Display the current domain.
        MessageBox.Show("The Client application is executing in:" & AppDomain.CurrentDomain.FriendlyName)
        Try
            'Create the remote object, and determine what domain it is 
            'executing in.  This line throws the error.
            Dim RemoteObj As New RemoteObjects.RemoteObject
            MessageBox.Show("The remote object is executing in: " & RemoteObj.GetActiveDomain)
        Catch ex As Exception
            Dim err As String
            err = ex.Message
            MessageBox.Show("Error :" & err)
        End Try

    End Sub
End Class

'code for the app.config in the bin/debug directory for the server host same directory as the exe

VB.NET:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.runtime.remoting>
        <application name="SimpleServer">
            <service>
                <activated type="RemoteObjects.RemoteObject, RemoteObjects" />
            </service>
            <channels>
                <channel ref="tcp server" port="8080" />
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>

'code for the app.config in the bin/debug directory for the client same directory as the exe

VB.NET:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.runtime.remoting>
        <application name="SimpleClient">
            <client url="tcp://localhost:8080/SimpleServer">
                <activated type="RemoteObjects.RemoteObject, RemoteObjects"/>
            </client>
            <channels>
                <channel ref="tcp client"/>
            </channels>
        </application>        
    </system.runtime.remoting>
</configuration>

The Remote Object class library dll. Both the client form project and server form project have references to the RemoteObject dll.

VB.NET:
Public Class RemoteObject
    Inherits MarshalByRefObject

    'Return the name of the current application domain.
    Public Function GetActiveDomain() As String
        Return AppDomain.CurrentDomain.FriendlyName
    End Function

End Class
 
I copied your code to a new solution and it executed without errors. Try a different port. If you get this error
Tcp channel protocol violation: expecting preamble.
then you most likely have some kind of server listening at port 8080 that is returning invalid data where the remoting object data would be expected. In that case it was strange you didn't get a SocketException from remoting server first that 'only one usage of socket address permitted'.
 
New Error

Thanks there was another system process using that port however now I am receiving an error stating:

No connection could be made because the target machine actively refused it 127.0.0.1:80805.

I used netstat to determine the list of tcp ports that were being used, and found 8085 was not also 8086 was not as well, but still received the same error after changing the port numbers in both config files and rebuilding the solution.
 
surely not port 80805? :) You would get that error in client if server is not started, also if the connection is blocked by a firewall, but that would seem strange inside the localhost.
 
New Error

sorry I meant port 8085 and port 8086:

I also have the solution setup so the server starts first, and then the client.
 
Last edited:
Back
Top