Beispiel #1
0
        public void Send(Session session, string data)
        {
            Task.Run(() =>
            {
                byte[] byteData = Encoding.UTF8.GetBytes(data);

                // Begin sending the data to the remote device.
                session.BeginSend(byteData, 0, byteData.Length, 0,
                    new AsyncCallback(SendCallback), session);
            });
        }
Beispiel #2
0
 public void BeginSend(byte[] byteData, int offset, int bufferSize, SocketFlags socketFlag, AsyncCallback asyncCallback, Session session)
 {
     client.BeginSend(byteData, offset, bufferSize, socketFlag, asyncCallback, session);
 }
Beispiel #3
0
 private void AcceptCallBack(IAsyncResult ar)
 {
     allDone.Set();
     listener = (Socket)ar.AsyncState;
     var handle = listener.EndAccept(ar);
     //handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
     var session = new Session(handle, bufferSize);
     Console.WriteLine("{0} connected at {1}", session.SessionID, session.Address);
     //Send(session, "hello client, welcome you!!!!!!!");
     UtilityHelper.RaiseEvent(OnNewClientConnected, session);
     session.BeginReceive(session.Buffer, 0, bufferSize, 0, new AsyncCallback(ReadCallback), session);
 }
Beispiel #4
0
 public void BeginReceive(byte[] buffer, int offset, int bufferSize, SocketFlags socketFlag, AsyncCallback ReadCallback, Session session)
 {
     client.BeginReceive(session.Buffer, 0, bufferSize, socketFlag, new AsyncCallback(ReadCallback), session);
 }