• Advertisement
Sign in to follow this  

[.net] Remoting server crashes when a client quits

This topic is 4508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement