逃夭结局主人公结局:C#编写的聊天程序调用dll出错

来源:百度文库 编辑:中科新闻网 时间:2024/05/07 06:37:52
这是我写的聊天程序执行到客户端的bool check=topic.addUser(nickname_txtbox.Text,ref textBox1,ref listBox1);是抛出异常,请问应怎样修改?
用到的服务器using System;
namespace com.icommware.PublishSubscribe
{

public class Topic:MarshalByRefObject
{

ArrayList userlist=new ArrayList();
ArrayList textboxlist=new ArrayList();
ArrayList listboxlist=new ArrayList();
///<summary>
///Input:string username(by value)and RichTextBox,ListBox(by refrense)
///Output:bool 'true'if username is unique else 'false'
///<summary>
public bool addUser(string user,ref RichTextBox textBox1,ref ListBox listBox1)
{
//check is username is present in the userlist'Arraylist'
bool test=userlist.Contains(user);
if(test)
{
//if present then Give the message to use and return 'false'
textBox1.Text+="This Nick has already been taken,try changing your Nick\n";
return false;
}
else
{
//user is unique hence add him to the userlist

userlist.Add(user);
//add the RichTextBox reference to textboxlist
textboxlist.Add(textBox1);
//add to existing users list
foreach(ListBox lb in listboxlist)
{
lb.Items.Add(user);
}
//add the ListBox reference to listboxlist
listboxlist.Add(listBox1);
//send to message only to the client connected
textBox1.Text+="Connected to server…\n";
//send message to everyone.
sendMessage(user+"has Joined Chat");
//add all the usernames in the ListBox of the client
foreach(string users in userlist)
{
listBox1.Items.Add(users);
}

return true;
}

}

public class TheServer
{

public static void Main()
{

int listeningChannel=1099;
//Creat a New HTTP Channel that listens on Port listeningChannel
//TCPChannel channel=new TCPChannel(listeningChannel);
HttpChannel channel=new HttpChannel(listeningChannel);
//Register the channel with the runtime
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Topic),
"com.icommware.PublishSubscribe.Topic",WellKnownObjectMode.Singleton);
//Expose the Calculator Object from this Server
//Keep the Server running until the user presses enter
Console.WriteLine("The Topic Server is up and running on port {0}",listeningChannel);
Console.WriteLine("Press enter to stop the server…");
Console.ReadLine();
}
}
}:
protected void nickname_btn_Click(object sender,System.EventArgs e)
{
try{

//coding manipulation starts here…
if(!connected)
{
int listeningChannel=0;
//Create and register a channel to communicate to the server
//The Client will use the port passed in as args to listen for callbacks
channel=new HttpChannel(listeningChannel);
ChannelServices.RegisterChannel(channel);

//Creat an instance on the remote server and call a method remotely
topic=(Topic)Activator.GetObject(typeof(Topic),//type to create
"http://localhost:1099/Topic.soap"//URI
);

username=nickname_txtbox.Text;
//add the user to the server
bool check=topic.addUser(nickname_txtbox.Text,ref textBox1,ref listBox1);