Kirk_G Posted September 7, 2003 Posted September 7, 2003 I am trying to get a simple server/multi-client program working but have run into a security exception. The server is a console program in C# that hosts a single class. The client is a forms program that has a ListBox to contain the messages, a TextBox to input a new message, and send button. When the client program loads it obtaines a reference to the MBR class hosted by the server. It then runs a method on the class called AddUser with the following signature ArrayList users = new ArrayList(); public void AddUser(ref ListBox newLB) { users.Add(newLB); } The thought was that when a new message was sent to the server by a client, the server would go through the ArrayList of referenced ListBoxes and update each one, thereby updating the ListBoxes on all the clients. This gives an exception though. I tried a simpler case of creating a new method on the served class with the following signature: public void ChangeString(ref string msg) { msg = @"Changed by Server"; } I then added string to the client side and set it value to @"Set by Client". If I display the string's value to the console before and after using it as the argument to the ChangeString method, I can see that it does indeed change when being set by ref to the server. My question is, why is a string different from a ListBox? Is there some security setting I can change to allow this to work? Is there a better way? Thanks in advance. Kirk Quote
obe1line Posted October 10, 2003 Posted October 10, 2003 The string works because the whole object is copied to the server and returned to the client. I assume that the ListBox object is only shallow copied (i.e. not all the contents). Since a listbox has an Items array that can hold any object, and those objects sit on the client it makes sense for the shallow copy to occur). You could pass a copy of the Item array as an array list to the server and this can be changed, then set the listbox items to the one returned from the server manually. Another option is to wrap the ListBox class and expose the ISerializable interface, but that is more complex... Hope this helps, Chris Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.