Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net.Sockets;
- using System.Net;
- using System.Text;
- class Program
- {
- static void Main(string[] args)
- {
- string name;
- string message;
- int bytesSend;
- byte[] bytes = new byte[1024];
- FileStream myFStream = new FileStream("temp.dat",FileMode.OpenOrCreate,FileAccess.ReadWrite);
- BinaryWriter binWr = new BinaryWriter(myFStream);
- Console.WriteLine("Для завершения работы клиента пропишите end");
- Console.Write("Введите ник:");
- name = Console.ReadLine();
- IPHostEntry ipHost = Dns.GetHostEntry("localhost");
- IPAddress ipAddr = ipHost.AddressList[1];
- IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11320);
- Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- sender.Connect(ipEndPoint);
- binWr.Write(name);
- bytesSend = sender.Send(Encoding.UTF8.GetBytes(name));
- Console.WriteLine("Соединение установлено!");
- Console.WriteLine();
- while (true)
- {
- message = Console.ReadLine();
- binWr.Write(message);
- bytesSend = sender.Send(Encoding.UTF8.GetBytes(message));
- if (message.Equals("end"))
- {
- sender.Close();
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment