Консольный чат - проблемы с подключением - C#
Формулировка задачи:
Что почитать, куда нюхать , куда смотреть , чтоб создать чат в консольном ?
я знаю вот эти библиотеки ( пространство имен, точно будут )
System.Net;
System.Net.Sockets;
System.IO;
Решение задачи: «Консольный чат - проблемы с подключением»
textual
Листинг программы
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Linq;
public class _Chat_Client_Version_1_0_{
public static void Main(){
Console.Title = "Chat Client Ver.1.0";
_Chat_Client_Initialization();
_Chat_Client_Connect_Repeat_:
try{
string _Chat_Client_Server_ = "";
string _Chat_Client_Message_ = "";
Int32 _Chat_Client_Port_ = 6112;
Console.WriteLine("Подключение к сети...");
TcpClient _Chat_Client_Client = new TcpClient(_Chat_Client_Server_, _Chat_Client_Port_);
Byte[] _Chat_Client_Data_ = System.Text.Encoding.ASCII.GetBytes(_Chat_Client_Message_);
// Stream stream = client.GetStream();
NetworkStream _Chat_Client_Stream_ = _Chat_Client_Client.GetStream();
_Chat_Client_Stream_.Write(_Chat_Client_Data_, 0, _Chat_Client_Data_.Length);
Console.WriteLine("Отправлено: {0}", _Chat_Client_Message_);
_Chat_Client_Data_ = new Byte[256];
String _Chat_Client_Response_Data_ = String.Empty;
Int32 bytes = _Chat_Client_Stream_.Read(_Chat_Client_Data_, 0, _Chat_Client_Data_.Length);
_Chat_Client_Response_Data_ = System.Text.Encoding.ASCII.GetString(_Chat_Client_Data_, 0, bytes);
Console.WriteLine("Получено: {0}", _Chat_Client_Response_Data_);
_Chat_Client_Stream_.Close();
_Chat_Client_Client.Close();}
catch (ArgumentNullException e){
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Ошибка аргументов сети: {0}", e);
Console.ForegroundColor = ConsoleColor.Green; }
catch (SocketException e){
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Ошибка разъёма сети: {0}", e);
Console.ForegroundColor = ConsoleColor.Green;}
Console.WriteLine("Press Enter to try again...");
Console.Read();
goto _Chat_Client_Connect_Repeat_;}
public static void _Chat_Client_Initialization(){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Добро пожаловать в Chat Client Ver.1.0.");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(new string('-',35));
Console.ForegroundColor = ConsoleColor.Green;}}