Sign in to follow this  
Saandman

[.net] Remoting server crashes when a client quits

Recommended Posts

I've set up the simplest remoting application where I register a service as single call using a tcp channel. The client connects just fine and can use the service but when I quit the client, the server crashes with an error trying to read what seems to be a null adress. Thing is, I've tried a few samples from tutorials and books and they too crash when I quit the client. I googled and found a user with the same problem, without an answer to the problem.. The service:
public class HelloService : MarshalByRefObject
	{
		public string hello()
		{
			Console.WriteLine("Hello!");
			return "Hello";
		}
	}


The server:
class HelloServer
	{
		static void Main(string[] args)
		{
			Console.WriteLine("Hit any key to exit at any time");

			try
			{
				TcpServerChannel channel = new TcpServerChannel(8088);

				ChannelServices.RegisterChannel(channel);
				RemotingConfiguration.RegisterWellKnownServiceType(typeof(HelloService), "HelloService", WellKnownObjectMode.SingleCall);
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
			}

			Console.ReadKey();
		}
	}


The client:
class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("Press any key to exit at any time");

			try
			{
				TcpClientChannel channel = new TcpClientChannel();

				ChannelServices.RegisterChannel(channel);
				HelloService service = (HelloService)Activator.GetObject(typeof(HelloService), "tcp://localhost:8088/HelloService");

				if (service != null)
					Console.WriteLine(service.hello());
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
			}

			Console.ReadKey();
		}
	}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this