Jump to content
  • Advertisement
Sign in to follow this  
Yosepp

[.net] Remoting frustration

This topic is 5397 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'm currently trying to figure out remoting. At first i used config files : worked like a dream. Then i switched to programmatical setup. And that's where the problems begun... Because my Server class, which connects the client and the server, has events in it, i had to change BinaryServerFormatterSinkProvider.TypeFilterLevel to full. But it still won't work! Now it gives me an SerializationException that it can't find assembly NetDragon.Client, but the error is given inside NetDragon.Client! I'll post the source as well.
   NetDragon.Server               NetDragon.Connection
       project          ----->          project               
This is the server gui            The connector class,
                                    contains Server(class)

-----> NetDragon.Client
           project
        The client gui



Client connection

			if(!connected)
			{
				string url = String.Format("{0}://{1}:{2}/Server", Config.Protocol, Config.ServerName, Config.RemotePort);
				BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
				serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
			
				BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
			
				IDictionary properties = new Hashtable();
				properties["port"] = Config.Port;
				properties["name"] = url;

				TcpChannel channel = new TcpChannel(properties, clientProvider, serverProvider);
				ChannelServices.RegisterChannel(channel);

				try
				{
			
					server = (Server)Activator.GetObject(typeof(NetDragon.Server), url); 
					server.OnDataReceived += new DataReceived(server_OnDataReceived);
					server.OnPlayerAdded += new NetDragon.PlayerEvent(server_OnPlayerAdded);
					server.OnPlayerRemoved += new NetDragon.PlayerEvent(server_OnPlayerRemoved);
					server.OnGMAdded += new GMEvent(server_OnGMAdded);

					if(server.GM == null)
						player = new GameMaster();
					else
						player = new NormalPlayer();

					server.AddPlayer(player);

					cmdConnectDisconnect.Text = "Disconnect";
					connected = true;
					cmdSend.Enabled = true;
				}
				catch(SocketException se)
				{
					if(se.ErrorCode == 10061)
						MessageBox.Show("Server is not running on target machine\n\tError code:" + se.ErrorCode ,"Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
			}
			else
			{
				server.RemovePlayer(player);

				server.OnDataReceived -= new DataReceived(server_OnDataReceived);
				server.OnPlayerAdded -= new NetDragon.PlayerEvent(server_OnPlayerAdded);
				server.OnPlayerRemoved -= new NetDragon.PlayerEvent(server_OnPlayerRemoved);
				server.OnGMAdded -= new GMEvent(server_OnGMAdded);

				server = null;

				cmdConnectDisconnect.Text = "Connect";
				connected = false;
				cmdSend.Enabled = false;
			}



Server connection
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
			provider.TypeFilterLevel = TypeFilterLevel.Full;
			IDictionary properties = new Hashtable();
			properties["port"] = port;
			properties["name"] = url;

			TcpChannel channel = new TcpChannel(properties, null,provider);
			RemotingConfiguration.RegisterWellKnownServiceType(typeof(NetDragon.Server), "Server", WellKnownObjectMode.Singleton);



and finally the connector (i'll post the whole file here)
namespace NetDragon
{
	public delegate void DataReceived(string data, MessageType type);
	public delegate void PlayerEvent(NetDragon.Player player);
	public delegate void GMEvent(NetDragon.GameMaster gm);

	public abstract class Player
	{
		string name;
		public string Name
		{
			get
			{
				return name;
			}
			set
			{
				name = value;
			}
		}
	}

	public class NormalPlayer : Player
	{
		int level;
		public int Level
		{
			get
			{
				return level;
			}
			set
			{
				level = value;
			}
		}

		public NormalPlayer()
		{
			Name = "Smokey McPot";
			Level = 1;
		}
	}

	public class GameMaster : Player
	{
		public void KillPlayer(Player player)
		{
		}

		public GameMaster()
		{
			Name = "Gamemaster";
		}
	}

	public class Server : MarshalByRefObject,IDisposable
	{
		public event DataReceived OnDataReceived;

		public event PlayerEvent OnPlayerAdded;
		public event PlayerEvent OnPlayerRemoved;

		public event GMEvent OnGMAdded;

		public ArrayList Players;
		public GameMaster GM; 

		public Server()
		{
			Players = new ArrayList(100);
		}

		public void SendData(string data, MessageType type)
		{
			OnDataReceived(data + Environment.NewLine, type);			
		}

		public void AddPlayer(Player player)
		{
			if(GM == null)
			{
				GM = player as GameMaster;
				OnGMAdded(GM);
			}
			else
			{
				Players.Add(player);
				OnPlayerAdded(player);
			}
		}

		public void RemovePlayer(Player player)
		{
			Players.Remove(player);
			OnPlayerRemoved(player);
		}

		#region IDisposable Members

		public void Dispose()
		{			
			RemovePlayer(GM);
			foreach(Player p in Players)
				RemovePlayer(p);

			Players.Clear();
		}

		#endregion
	}

	public enum MessageType
	{
		Normal,
		OOG,
		GM,
		Server
	}
}



I'm using C# and .NET 1.1 Thanks for any help! [Edited by - Yosepp on October 6, 2004 2:42:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
It might be just that you have set the project to reference the client dll, and that isn't there. I guess that doesn't matter so much on the server side - but make sure that the server does not have to explicitly use anything within the client.

So try adding the client dll in the same directory as your server executable.

Also careful about proxies and things - depending on how you've done this - I know SOAP creates it's own cut down version of the class for transmission... and that class may have the same name but exist in a different namespace and thus be different... and one part of your application could be looking at one version of that class, and the other bit another bit.

Share this post


Link to post
Share on other sites
I assume by client.dll you mean the remotable object, or what... The remotable dll(NetDragon.Connection.dll) is added to Client and Server via Add reference->Project->NetDragon.Connection.dll, so it's copied to Client folder and server folder every build, plus on every build all the output files are copied to one directory. As far as i know i'm not using SOAP, but am doing it the binary way, but now that i look at it, i really don't know is it binary or soap. By the way, when i replace the line server = (Server)Activator.GetObject(typeof(NetDragon.Server), url); with server = new Server(); , then it runs fine, but when running multiple clients, each client is on it's own : they aren't connected.
I should have provided more info too.
The error is in the client connection, on the line server.OnPlayerAdded += new NetDragon.PlayerEvent(server_OnPlayerAdded);
Oddly enough, the line just above, server.OnDataReceived += new DataReceived(server_OnDataReceived); doesn't cause an exception. Also, most exceptions that i receive about remoting are traced to that line (OnPlayerAdded).
I've uploaded the whole project here.
EDIT:Fixed the link.

Anyone???

[Edited by - Yosepp on October 8, 2004 6:19:30 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!