/// <inheritdoc />
protected override void WriteBytesToConnection(byte[] bytes)
{
- //Pack
- SocketAsyncEventArgs args = new SocketAsyncEventArgs();
- args.SetBuffer(bytes, 0, bytes.Length);
- args.RemoteEndPoint = RemoteEndPoint;
-
lock (socketLock)
{
if (State != ConnectionState.Connected && State != ConnectionState.Connecting)
try
{
- socket.SendToAsync(args);
+ socket.BeginSendTo(
+ bytes,
+ 0,
+ bytes.Length,
+ SocketFlags.None,
+ RemoteEndPoint,
+ delegate (IAsyncResult result)
+ {
+ try
+ {
+ lock (socket)
+ socket.EndSendTo(result);
+ }
+ catch (SocketException e)
+ {
+ HandleDisconnect(new HazelException("Could not send data as a SocketException occured.", e));
+ }
+ },
+ null
+ );
}
catch (ObjectDisposedException)
{
/// <param name="endPoint">The endpoint to send to.</param>
internal void SendData(byte[] bytes, EndPoint endPoint)
{
- SocketAsyncEventArgs args = new SocketAsyncEventArgs();
- args.SetBuffer(bytes, 0, bytes.Length);
- args.RemoteEndPoint = endPoint;
-
try
{
lock (listener)
- listener.SendToAsync(args);
+ {
+ listener.BeginSendTo(
+ bytes,
+ 0,
+ bytes.Length,
+ SocketFlags.None,
+ endPoint,
+ delegate (IAsyncResult result)
+ {
+ listener.EndSendTo(result);
+ },
+ null
+ );
+ }
}
catch (SocketException e)
{