我的代码:
public ChatServer()
{
//create our nickname and nickname by connection variables
nickName = new Hashtable(100);
nickNameByConnect = new Hashtable(100);
//create our TCPListener object
chatServer = new System.Net.Sockets.TcpListener(4296);
//check to see if the server is running
//while (true) do the commands
while (true)
{
chatServer.Start();
if (chatServer.Pending())
{
Chat.Sockets.TcpClient chatConnection = chatServer.AcceptTcpClient();
Console.WriteLine("You Are Connected");
DoCommunicate com = new DoCommunicate(chatConnection);
}
}
}
public static void SendMsgToAll(string nick, string msg)
{
StreamWriter writer;
ArrayList remove = new ArrayList(0);
Chat.Sockets.TcpClient[] tcpClient = new Chat.Sockets.TcpClient[ChatServer.nickName.Count];
ChatServer.nickName.Values.CopyTo(tcpClient, 0);
从我上面的代码中,我们可以看到有 2 种方法 i- ChatServer ii- SendMsgToAll。所以当我尝试用Chat.Sockets.TcpClient[] tcpClient = new Chat.Sockets.TcpClient[ChatServer.nickName.Count];
第二种方法写线时
它给出了以下错误:
ChatSerevr() 是在给定上下文中无效的方法。
我用谷歌搜索,但找不到正确的解决方案。提前致谢