protected void AcceptCallback(IAsyncResult Result) { Next.Set(); Socket S = (Socket)Result.AsyncState; Socket ClientSocket = S.EndAccept(Result); S.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, 0)); State state = new State(); state.ClientSocket = ClientSocket; ClientSocket.BeginReceive(state.Buffer, 0, State.BufferSize, 0, new AsyncCallback(RecieveCallback), state); }
protected override void Send(string Message,State ConnectionState) { byte[] Buffer = Encoding.ASCII.GetBytes(Message); ConnectionState.ClientSocket.BeginSendTo(Buffer, 0, Buffer.Length, 0, (ConnectionState as DatagramState).EndPoint, new AsyncCallback(SendCallback), ConnectionState); }
protected abstract void Send(string Message, State ConnectionState);
//send back the result protected override void Send(string Message, State ConnectioState) { byte[] Data = Encoding.ASCII.GetBytes(Message); ConnectioState.ClientSocket.BeginSend(Data, 0, Data.Length, 0,new AsyncCallback(SendCallback), ConnectioState.ClientSocket); }