Wrox Programmer Forums
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2008, 05:30 AM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to mahen_pali Send a message via Yahoo to mahen_pali
Default Remoting in C#

Hi to all members
My problem is related to remoting in c#. there are three files
c.cs Customer file code
s.cs Server File Code
o.c Server side code which we call in C.CS

C.CS File
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class ccc
{
    public static void Main()
    {
      TcpChannel c = new TcpChannel();
      ChannelServices.RegisterChannel(c);
      zzz a = (zzz)Activator.GetObject(typeof(zzz), "tcp://localhost:8085/eee");
      if (a == null)
          System.Console.WriteLine("Could not locate server");
      else
        Console.WriteLine(a.abc());
    }
}

S.CS
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class sss
{
    public static void Main()
    {
          TcpChannel c = new TcpChannel(4444);
          ChannelServices.RegisterChannel(c,true);
          RemotingConfiguration.RegisterWellKnownServiceType (
          Type.GetType("zzz,o"), "eee", WellKnownObjectMode.SingleCall);
          System.Console.WriteLine("Press <enter> to exit...");
          System.Console.ReadLine();
    }
 }


O.CS
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
public class zzz : MarshalByRefObject
{
    public zzz()
    {
        Console.WriteLine("Constructor");
    }
    ~zzz()
    {
        Console.WriteLine("Destructor");
    }
    public String abc()
    {
          Console.WriteLine("Vijay Mukhi2");
          return "Sonal";
    }
  }


When I Comple and execute . it’s compile properly but not execute client code.
Server class execute successfully and give
 o/p Press <enter> to exit...

when I execute client code it’s this error
Unhandled Exception: System.Net.Sockets.SocketException: No connection could be
made because the target machine actively refused it 127.0.0.1:8085

Server stack trace:
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.Runtime.Remoting.Channels.RemoteConnection. CreateNewSocket(EndPoint
 ipEndPoint)
   at System.Runtime.Remoting.Channels.RemoteConnection. CreateNewSocket()
   at System.Runtime.Remoting.Channels.SocketCache.GetSo cket(String machinePortA
ndSid, Boolean openNew)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTran sportSink.SendRequestWit
hRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTran sportSink.ProcessMessage
(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITranspor
tHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryClientForma tterSink.SyncProcessMess
age(IMessage msg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData& msgDa
ta, Int32 type)
   at zzz.abc()
   at ccc.Main()

My Problem : I am not getting which port I can use for remoting please help me to solve this problem

Thanks


mahendra singh
 
Old February 24th, 2009, 05:15 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default re:Remoting in C#

I see two potential problems in your remote server application (S.CS). When you declare and instantiate the TcpChannel you use a different port than the client application uses.

Code:
TcpChannel c = new TcpChannel(4444);
The second may not be critical but the Type.GetType("zzz,o") function should have as an argument "<namespace>.<class>, <namespace>". I see the class "zzz" but I don't see that you assigned a namespace in the code you posted.

I think the main reason why it rejects your client application connection is the port though.
__________________
What you don\'t know can hurt you!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remoting in c# mahen_pali C# 0 November 17th, 2008 10:17 AM
Remoting bhavana .NET Framework 1.x 0 November 12th, 2007 04:20 AM
remoting caribbean Pro VB.NET 2002/2003 0 May 16th, 2006 12:11 PM
Remoting manisha2578 VS.NET 2002/2003 1 June 29th, 2005 06:59 AM
Remoting.... kk_katepally General .NET 0 December 21st, 2004 05:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.