コード例 #1
0
		public override void Send(byte[] data, string to = "")
		{
			try
			{
				var endpoint = IPEndPoint.Parse(to);
				var state = new ReceiverState
				{
					Port = endpoint.Port,
					Socket = ServerSocket,
					Ip = endpoint.Address.ToString()
				};

				ServerSocket.BeginSendTo(data, 0, data.Length, SocketFlags.None, endpoint, OnSendToCallback, state);
				OnReportingStatus(StatusCode.Info, $"Started sending {data.Length} bytes to {endpoint} via UDP socket");
			}
			catch (ObjectDisposedException)
			{
			}
			catch (SocketException socketException)
			{
				OnCaughtException(socketException, EventCode.Send);
			}
			catch (Exception e)
			{
				OnCaughtException(e, EventCode.Other);
			}
		}
コード例 #2
0
ファイル: UdpServer.cs プロジェクト: gkurbesov/C4C.Socket
 /// <summary>
 /// Отправка масива байт
 /// </summary>
 /// <param name="client_id">ID клиента, полученный при событии подкулючения</param>
 /// <param name="data">массив байт для отправки</param>
 public void Send(EndPoint client_point, byte[] data)
 {
     try
     {
         if (ServerSocket != null && IsListeningStatus)
         {
             ServerSocket.BeginSendTo(data, 0, data.Length, SocketFlags.None, client_point,
                                      new AsyncCallback(SendCallback), client_point);
         }
     }
     catch (SocketException exc)
     {
         CallErrorServer(ServerErrorType.SendDataError, exc.Message);
     }
     catch (Exception exc)
     {
         CallErrorServer(ServerErrorType.SendDataError, exc.Message);
     }
 }