   .Net Remoting Question (C#)
  I am trying to get .net remoting working for my C# game. So far I opened a new project to try and get the remoting working seperately before I try and merge it with my 3D game code. I have 3 projects in the solution, a client form, a server form, and a "transport helper" shared class library object, as per the instructions I've read on a few online tutorials. The server and client appear to be connecting properly, and I register the channel and all that. I'll post the relevant code at the end, it's not very long, if that will help people answer my question!The question is where do I put the "server" code? It appears I can call the shared dll functions from the client...do I put class-wide variables in the shared dll and then have all the clients update them through the functions? Or is there some other way to do it? I can't quite figure it out...I did set the mode to "Singleton" in the registerservices call, so hopefully that will mean all the clients access one shared object, and all be able to update an ArrayList of game object locations as well as read said list?Anyways, I'll check back here so if anyone can help but needs more info I'll provide it. You can also see my game at http://spaceracer2025.blogspot.com , this net code isn't there but my old crappy socket code is there as is my halfway decent single player asteroids clone with a bigger playfield and zoom-in-zoom-out, 3D models with 2D game code in D3D. (I'm adding multiplayer support to the asteroids clone now!) Here is the C# .net remoting code I have so far:SharedDll:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;using System.Windows.Forms;//do I put the server code in here???namespace SpaceRacersAsteroids{    public class TransportHelper : MarshalByRefObject    {   public TransportHelper()   {  Console.WriteLine("TransportHelper Constructor Called");   }   public String TestFunction()   {  Console.WriteLine("TestFunction in TransportHelper Called");  return "TestFunction1857";   }    }}Client:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;namespace SpaceRacersAsteroids{    public partial class Form1 : Form    {   TcpChannel chan;   public Form1()   {  InitializeComponent();  chan = new TcpChannel();  ChannelServices.RegisterChannel(chan);  TransportHelper remObject = (TransportHelper)Activator.GetObject( typeof(SpaceRacersAsteroids.TransportHelper), "tcp://localhost:6667/AsteroidsServer");  if (remObject == null) Console.WriteLine("cannot locate server");  else   //   remObject.ReplyMessage("You there?"); Console.WriteLine("Can locate server!!!");}    }}Server:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Tcp;using SpaceRacersAsteroids;namespace SpaceRacersAsteroids{    public partial class MainServerForm : Form    {   TcpChannel chan;   public MainServerForm()   {  InitializeComponent();  chan = new TcpChannel(6667);  ChannelServices.RegisterChannel(chan);    //register channel  RemotingConfiguration.RegisterWellKnownServiceType(typeof(TransportHelper),"AsteroidsServer",WellKnownObjectMode.Singleton);   }    }}I hope someone can help me! Also if this code is helpful to you, feel free to use it or learn from it. You're always welcome to come donate me money on my web site mentioned above. :)   
  Funnily enough I've been playing with remoting too and run across the same questions...Im at home so I dont have the links in front of me, but what I found useful was a tutorial on using an interface along with the dll. This allowed the client side to only need the interface dll and not the library dll on it, so the client cannot see the actual code if they tried to reverse engineer it.My situation is a little different though as i want to use remoting for my servers to talk to each other. I essentially have a "server" object that runs on each server and is used for server to server communication.The other thing I found useful is to instantiate the local server object and marshal that instead of letting a client create it, i wish i had the code in front of me to show the exact syntax... heh I love remote desktop found it... forgive the code it's VB.net and i was drinking and testing things :)Imports SystemImports System.Runtime.RemotingImports System.Runtime.Remoting.ChannelsImports System.Runtime.Remoting.Channels.TcpImports NodeControllerImports NodeModule Main    Public CONTROLLER As New ClsNodeController    Public LISTEN As Boolean = True    Public CON As New Form1    Public Sub Main()   CON.Show()   CON.WriteLine("CONTROLLER: Registering controller object on network")   ChannelServices.RegisterChannel(New TcpChannel(20000), False) RemotingServices.Marshal(CONTROLLER, "CONTROLLER")   Dim TEST As New TestClass   RemotingServices.Marshal(TEST, "TEST")   TEST.TheName = "POOBAREgfdsgsg"   CON.WriteLine("CONTROLLER: Node Controller started on port 20000")   Do While LISTEN = True  Application.DoEvents()   Loop   Form1.Hide()   Form1.Dispose()    End SubEnd Module[\code]The main thing to see is that I instantiate the CONTROLLER object at startup, this object is the one that will be available to other servers. then I use "RemotingServices.Marshal(CONTROLLER, "CONTROLLER")" to use the CONTROLLER object as the one being shared. So instead of one being created when someone connects, I now have an object that the main code can use and interact with whether there is someone connected or not...I'm still tossing around using remoting versus a reliable UDP object I created, both have strengths and weaknesses so I'm still playing with both ideas...EDIT: And I almost forgot, The problem I found when NOT using an interface DLL is that the object in the DLL library was on it's own, it couldnt access back into the main code. When I went to using the interface DLL I could put my object  back into the main project and then "implement" the interface in the server object. So in other words I have an object in my main code, that runs whether someone is connected or not, and has full access to the main code..Now I dont know if the way i've done it is right or wrong, like I said I'm still learning too :);  Dot net remoting (or Java remoting) is almost entirely unsuitable for games.The security model is not a good match for free internet distribution.The communication model is way too heavyweight, and not optimized for latency.I highly recommend you try something else, if you actually want to work on a networked game.If you want to work on remoting, just to learn it, then choose some other test application.;  These are very serious accusations against .net remoting! Are these verifiable? How is sending bits via remoting less secure than using sockets or some other API? How is it not optimized for latency, and how much overhead does it add as a %? Are we talking 5% more latency over sockets on a packet or 500% more? My game has pretty low network demands, so a little extra overhead in exchange for less bugs and shorter code time sounds good, especially if short efficient code lets me make the network code more optimized...I'm a one man team, so I kind of want to get this game published soon...security isn't a huge issue, I'm publishing the source too to help bring more people to my website and game, and also to help assure people that I am not giving them a trojan. My userbase is still pretty small, I got 8 returning visitors today and 9 total, so I think that's a good thing. Also I have google ads on the site and a donations button, so I might actually make some money writing code some day. I would love to make a popular game, and am right now updating the single player asteroids clone to make a vaguely eve-online themed asteroids clone, I got the form clients to connect to each other and post a client count to each client, I just signed up for a free dyndns account so I can host the server on my PC (or with godaddy.com for $30 per month if too many people play and my cable breaks...hope that happens lol) and hopefully get a client base going...although that's still pretty far off...   ;  I didn't say remoting was *less secure*, I said the security model was a poor match. If you think you can manage internet distribution with thousands of users over the .NET remoting security model, by all means, go right ahead! Let me know how that works out.However, remoting is built on an RPC assumption, which means that one side of the connection requests the other side to execute some code. If you read the documentation on .NET remoting, you see that, to use it, you have to have FullTrust permissions. This means that any remote user can execute code in your server with FullTrust. Handing authentication and authorization in this model is a lot more error-prone, and a mistake opens a lot bigger hole, than in a message-based model where each individual message is directly specified.Regarding efficiency: Just take a packet sniffer to the protocol, then take a packet sniffer to the protocol of something tuned for games, like Quake 3 or World of Warcraft, and you will see the difference. It's many hundreds of percent of difference.If you want something ready-made, there's a C# game networking library called Lidgren that has been mentioned several times on this forum (I haven't used it myself).   ;  Are you claiming that if I run the server on my computer, then any client can run any arbitrary code on my computer? I do not think that is accurate. I will run the server on my computer and send you my IP address, can you then run code on my PC? How is this accomplished? Even assuming you have the source, all you could do is call the functions....is this security hole documented somewhere, or is it theoretical?How exactly can I compare the network traffic of Quake3 to my game? They are two totally different programs, and the bulk of the traffic flow will be dictated by the game code, not the API (sockets vs. remoting) used. I'm not sure how I could easily answer this question with a packet sniffer in any way. Are there any official tests on this? What is your source on this information? Have you used .net remoting personally, or did you read about it somewhere? Where did you read about it, or how did you speed test it personally?I'm sorry, but I think I'm going to ignore what you're saying and keep using C# and .net remoting for a variety of subtle reasons. That being said, maybe when I get to 1k simultaneous users I'll use something else...   