Greetings to all! There are 2 applications, client and server, between them via the Internet transfer of text data from the client to the server. Please advise how it is better to organize a transfer between them so that when the connection is broken, you can easily catch this gap and continue the transfer from the previous place when connected. I try to implement it now on sockets, I rested against the problem that I can not catch the disconnection. My sample client code:

try { IPEndPoint EndPoint = new IPEndPoint(IPAddress.Parse(IP.Text), 5555); Socket Connector = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Connector.Connect(EndPoint); //Отправляем сообщение Byte[] SendBytes = Encoding.Default.GetBytes(Message); Connector.Send(SendBytes); Connector.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } 

Server code:

 TcpListener Listen = new TcpListener(5555); Listen.Start(); Socket ReceiveSocket; while (true) { try { //Пришло сообщение ReceiveSocket = Listen.AcceptSocket(); Byte[] Receive = new Byte[256]; using (MemoryStream MessageR = new MemoryStream()) { //Работа с данными } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } } 

With such code, when the server is unavailable, the client tries to send several messages and several errors take off.

    0