C#不一致的可访问性:参数类型比方法

时间:2015-07-08 20:54:33

标签: c#

我收到错误我无法找到解决方法

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MITM_Omar
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        public void button1_Click(object sender, EventArgs e)
        {
          ClientListener Client = new ClientListener();
            Client.ClientConnected += clientconnect;
        }
        public void clientconnect(ClientListener client)
        {
            ServeurListener Serveur = new ServeurListener("213.248.126.39", 5555);
            client.associated = Serveur;
            Serveur.associated = client;
            client.onReception += forwadtoserver;
            Serveur.onReception += forwadtoclient;
            Serveur.connect(); 
        }
        public void forwadtoclient(ServeurListener sender, byte[] buffer)
        {
            sender.associated.send(buffer);
        }
        public void forwadtoserver(ClientListener sender, byte[] buffer)
        {
            sender.associated.send(buffer);
        }
    }
}

我收到错误不一致的可访问性:参数类型' MITM_OMAR.ClientListener'比方法更容易访问' MITM_OMAR.Form1.clientconnect(MITM_OMAR.ClientListener)

这是客户端侦听器类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Threading;
using System.Net;
namespace MITM_Omar
{
    class ClientListener
    {
        public Socket _Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        public Thread _ConnectionThread;
        public Thread _ReceptionThread;


        public delegate void onClientActionEventHandler(ClientListener client);
        public event onClientActionEventHandler ClientConnected;


        public delegate void onTravellingDataEventHandler(ClientListener sender, byte[] buffer);
        public event onTravellingDataEventHandler onReception;
        public ServeurListener associated;
       public ClientListener()
        {
            _ConnectionThread = new Thread(new ThreadStart(accept));
            _Socket.Connect("127.0.0.1", 5555);
            _ConnectionThread.Start();
            _ReceptionThread = new Thread(new ThreadStart(Reception));
            _ReceptionThread.Start();
        }
        public void accept()
        {
            while (true)
            {
                Socket socket = _Socket.Accept();
                if (ClientConnected != null)
                {
                    ClientConnected(this);
                }
            }

        }
        public void send(byte[] data)
        {
            _Socket.Send(data);


        }
        public void Reception()
        {
            // On reçoit les données tant qu'on est connecté.
            while (_Socket.Connected)
            {
                // On crée notre buffer dynamique.
                byte[] _buffer = new byte[_Socket.Available];

                // Si le buffer n'est pas vide, on le parse.
                if (_buffer.Length != 0)
                {
                    _Socket.Receive(_buffer); // Récéption des données.
                    if (onReception != null) onReception(this, _buffer); // un event qui dit qui a reçu des données et le tableau de bytes reçu

                }
            }
        }


    }
}

1 个答案:

答案 0 :(得分:4)

让你的课程公开。

public class ClientListener
...

如果未明确指定类,则默认访问类是内部的。内部不如公众访问,因此您会收到错误。