Ошибка: Тип Chat уже определяет член с именем "Listen" с теми же типами параметров - C#
Формулировка задачи:
Здравствуйте!
Делаю чат на C#, но у меня выскакивает ошибка! Использую класс "Chat.cs":
А вот код мэйна:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Chat
{
private UdpClient udpclient;
private IPAddress multicastaddress;
private IPEndPoint remoteep;
public void SendOpenMessage(string data);
public void Listen();
public Chat()
{
multicastaddress = IPAddress.Parse("239.0.0.222"); // один из зарезервированных для локальных нужд UDP адресов
udpclient = new UdpClient();
udpclient.JoinMulticastGroup(multicastaddress);
remoteep = new IPEndPoint(multicastaddress, 2222);
}
public void SendMessage(string data)
{
Byte[] buffer = Encoding.UTF8.GetBytes(data);
Byte[] encrypted = Encrypt(data);
udpclient.Send(buffer, buffer.Length, remoteep);
udpclient.Send(encrypted, encrypted.Length, remoteep);
}
public void Listen()
{
UdpClient client = new UdpClient();
client.ExclusiveAddressUse = false;
IPEndPoint localEp = new IPEndPoint(IPAddress.Any, 2222);
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.ExclusiveAddressUse = false;
client.Client.Bind(localEp);
client.JoinMulticastGroup(multicastaddress);
Console.WriteLine("\tListening started");
string formatted_data;
while (true)
{
Byte[] data = client.Receive(ref localEp);
formatted_data = Decrypt(data);
formatted_data = Encoding.UTF8.GetString(data);
Console.WriteLine(formatted_data);
}
}
private byte[] Encrypt(string clearText, string EncryptionKey = "123")
{
byte[] clearBytes = Encoding.UTF8.GetBytes(clearText);
byte[] encrypted;
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); // еще один плюс шарпа в наличие таких вот костылей.
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
encrypted = ms.ToArray();
}
}
return encrypted;
}
private string Decrypt(byte[] cipherBytes, string EncryptionKey = "123")
{
string cipherText = "";
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.UTF8.GetString(ms.ToArray());
}
}
return cipherText;
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Chat chat = new Chat();
Thread ListenThread = new Thread(new ThreadStart(chat.Listen));
ListenThread.Start();
string data = Console.ReadLine();
chat.SendMessage(data);
}
}
}Ошибка: Тип "ConsoleApplication2.Chat" уже определяет член с именем "Listen" с теми же типами параметров
Как решить эту проблему?Решение задачи: «Ошибка: Тип Chat уже определяет член с именем "Listen" с теми же типами параметров»
textual
Листинг программы
public void SendOpenMessage(string data); public void Listen();