我现在做一个聊天程序
遇到这样的问题
using System.Net;
using System.Net.Sockets;
在程序中有个Client cl = (Client) clients[n];
引用我也有添加啊!可为什么还这样提示
还有个够造函数中也出现了
private void SendToClient(Client cl,string message)
{}
其中的Client提示同样的问题!
我不知道是怎么回事,请高手指点下
在线等,谢谢
如果有需要更详细的信息也给提供
QQ269733087也可以加聊

解决方案 »

  1.   

    Client这个类你是在哪定义的,你要把这个给引用进来啊!
      

  2.   

    没有client这个类啊,我想这个因该是数据类型,因为在构造函数中
    private   void   SendToClient(Client   cl,string   message) 
     有啊!
     我也有引用啊!就是不知道什么原因,我把代码发来大家帮看看吧!
    ————————————————————————————————————
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Collections;
    namespace ChatServer
    {
        public partial class fromServer : Form
        {
            public fromServer()
            {
                InitializeComponent();
                clients = new Arraylist();
                processor = new Thread(new ThreadStart(StartListening));
                processor.Start();
            }
            private ArrayList clients;
            private int listenport = 5555;
            private Thread processor;
            private Socket clientsocket;
            private Thread clientservice;
            private void ServiceClient()
            {
                Socket client = clientsocket;
                bool keepalive = true;
                while (keepalive)
                {
                    Byte[] buffer = new Byte[1024];
                    client.Receive(buffer);
                    string clientcommand = System.Text.Encoding.ASCII.GetString(buffer);
                    string[] tokens = clientcommand.Split(new Char[] { '|' });
                    Console.WriteLine(clientcommand);
                    if (tokens[0] == "CONN")
                    {
                        for (int n = 0; n < clients.Count; n++)
                        {
                            Client cl = (Client)clients[n];                    }
                    }
                }
            }
            protected override void  OnClosing(CancelEventArgs e)
            {
                try
                {
                    for (int n = 0; n < clients.Count; n++)
                    {
                        Client cl = (Client)clients[n];                }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                base.OnClosed(e);
            }
            private void SendToClient(Client cl, string message)
            {
                try
                {
                    byte[] buffer = System.Text.Encoding.ASCII.GetBytes(message.ToCharArray());
                    
                }
            }    }
    }
    ————————————————————————————————————————
    代码有点乱,初学,有些不知道什么意思,所以自己先试下,可按照说上做也会出错
     还不知道是那里出错了!
      

  3.   

    我在baidu上也有搜索过,有的说是系统DLL的问题!
     我也不太清楚
     程序集我也有啊!
    是不是
    using Sysetem.Net.Sockets;啊!
     
      

  4.   

     我怀疑那是不是错的·
     那类型Client   是不是这个?
    private   void   SendToClient(Client   cl,   string   message) 
    或者是别的类型呢!
    想ing
     
      

  5.   

    类型之后敲上小数点,就可以弹出下拉菜单,如果弹不出来,就是不认这个类。
    原因可能是 internal 等作用域访问不到,或名字拼错了(特别是大小写),或没在 cs 文件里使用using 命名空间,即使你的类源码在同一 cs 文件中,也要在开头加上 using 引用一下。再就是引用里没有加载相对应的 dll 程序集。
      

  6.   

    实在找不到错误啊!
     我就是怀疑这个类型是不是错勒
     我把这个聊天程序的服务器端的代码都发过去
     大家帮看看,谢谢啊!
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Collections;
    namespace ChatServer
    {
        public partial class fromServer : Form
        {
            public fromServer()
            {
                InitializeComponent();
                clients = new Arraylist();
                processor = new Thread(new ThreadStart(StartListening));
                processor.Start();
            }
            private ArrayList clients;
            private int listenport = 5555;
            private TcpListener listener;
            private Thread processor;
            private Socket clientsocket;
            private Thread clientservice;
            private void ServiceClient()
            {
                Socket client = clientsocket;
                bool keepalive = true;
                while (keepalive)
                {
                    Byte[] buffer = new Byte[1024];
                    client.Receive(buffer);
                    string clientcommand = System.Text.Encoding.ASCII.GetString(buffer);
                    string[] tokens = clientcommand.Split(new Char[] { '|' });
                    Console.WriteLine(clientcommand);
                    if (tokens[0] == "CONN")
                    {
                        for (int n = 0; n < clients.Count; n++)
                        {
                            Client cl = (Client)clients[n];
                            SendToClient(cl, "JOIN|" + tokens[1]);
                        }
                        EndPoint ep = client.RemoteEndPoint;
                        Client c = new client(tokens[1], ep, clientservice, client);
                        clients.Add(c);
                        string message = "LIST|" + GetChatterList() + "\r\n";
                        SendToClient(c, message);
                        lblClients.Items.Add(c);                }
                    if (tokens[0] == "CHAT")
                    {
                        for (int n = 0; n < clients.Count; n++)
                        {
                            Client cl = (Client)clients[n];
                            SendToClient(cl, clientcommand);
                        }
                    }
                    if (tokens[0] == "PRIV")
                    {
                        for (int n = 0; n < clients.Count; n++)
                        {
                            Client cl = (Client)clients[n];
                            SendToClient(cl, clientcommand);
                        }
                    }
                    if (tokens[0] == "PRIV")
                    {
                        string destclient = tokens[3];
                        for (int n = 0; n < clients.Count; n++)
                        {
                            Client cl = (Client)clients[n];
                            if (cl.Name.CompareTo(tokens[3]) == 0)
                                SendToClient(cl, clientcommand);
                            if (cl.Name.CompareTo(tokens[1]) == 0)
                                SendToClient(cl, clientcommand);
                            if (tokens[0] == "GONE")
                            {
                                int remove = 0;
                                bool found = false;
                                int c = clients.Count;
                                for (int n = 0; n < c; n++)
                                {
                                    Client cl = (Client)clients[n];
                                    SendToClient(cl,clientcommand);
                                    if(cl.Name.CompareTo(tokens[1])==0)
                                    {
                                        remove = n;
                                        found = true;
                                        lblClients.Items.Remove(cl);
                                    }
                                }
                                if(found)
                                {
                                    clients.RemoveAt(remove);
                                    client.Close();
                                    keepaliv=false;
                                }
                            }
                        }
                    }
                }
            }
           
            protected override void  OnClosing(CancelEventArgs e)
            {
                try
                {
                    for (int n = 0; n < clients.Count; n++)
                    {
                        Client cl = (Client)clients[n];
                        SendToClient(cl, "QUIT|");
                        cl.Sock.Close();
                        cl.CLThread.Abort();                }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                base.OnClosed(e);
            }
            private void StartListening()
            {
                listener = new TcpListener(listenport);
                listener.Start();
                while (true)
                {
                    try
                    {
                        Socket s = listener.AcceptSocket();
                        clientsocket = s;
                        clientservice = new Thread(new ThreadStart(ServiceClient));
                        clientservice.Start();                }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());                }
                }
            }
            private void SendToClient(Client cl, string message)
            {
                try
                {
                    byte[] buffer = System.Text.Encoding.ASCII.GetBytes(message.ToCharArray());
                    cl.Sock.Send(buffer, buffer.Length, 0);            }
                catch (Exception e)
                {
                    cl.Sock.Close();
                    cl.CLThread.Abort();
                    clients.Remove(cl);
                    lblClients.Items.Remove(cl.Name + ":" + cl.Host.ToString());
                }
            }
            private string GetChatterList()
            {
                string chatters = "";
                for (int n = 0; n < clients.Count; n++)
                {
                    Client cl = (Client)clients[n];
                    chatters += "|";            }
                chatters.Trim(new char[] { '|' });
                return chatters;
            }    }
    }
      

  7.   

    这个问题是这样的,你就没有定义Client这个类,当然就会出现这样的提示了。我猜你这个代码是贴别人的吧,因为C#里处理socket的只有TcpClient和Socket,里面都没有类似.Sock的属性.你可以把Client这个类替换成TcpClient,稍改一下就可以通过了
      

  8.   

    谢谢你啊!wisecameo
    是少了CLIEN类,呵呵!
      

  9.   

    我想问一下  关于这个项目的客户端  其中一段程序是CreateConnection();  
     
                if (connected)  
                {  
                    StoreforServer();  
                    recThread = new Thread(new ThreadStart(ReceiveChat));  
                    recThread.Start();  
     
                    btn_send.Enabled = true;  
                    btn_shutdown.Enabled = true;  
                    btn_connect.Enabled = false;  
                    btn_savemessage.Enabled = true;  
                    
                    rtfEditor1.RtfDocument= "";                    
                }  
            }  
    请问这个rtfEditor1.RtfDocument= "";  是什么意思?