public void SendData(string data, TransmitedDataType dataType)
        {
            if (IsConnected)
            {
                try
                {
                    if (dataType != TransmitedDataType.Unknown)
                    {
                        data = "C" + (int)dataType + data;
                    }
                    if (data.Length < BufferSize)
                    {
                        data = data.PadRight(BufferSize);
                    }
                    ASCIIEncoding asen = new ASCIIEncoding();
                    byte[]        ba   = asen.GetBytes(data);
                    Console.WriteLine("Transmitting.....");

                    connectionStream.Write(ba, 0, ba.Length);
                    connectionStream.EndWrite(null);
                    networkError = null;
                }
                catch (Exception e)
                {
                    networkError = e;
                    State        = NetworkStates.NetworkError;
                }
            }
        }
            protected void WriteCallback(IAsyncResult ar)
            {
                ResultHandler rh = (ResultHandler)ar.AsyncState;

                mStream.EndWrite(ar);
                rh(mHandle, MoSync.Constants.CONNOP_WRITE, 1);
            }
Beispiel #3
0
        public void Write(byte[] buffer, int offset, int count)
        {
            var async = _stream.BeginWrite(buffer, offset, count, null, null);

            _stream.EndWrite(async);
            async = null;
            //_stream.Write(buffer,offset,count);
        }
        void TransparentStreamWriteRequestMessageReceived(TransparentStreamMessageBase transparentStreamMessageBase)
        {
            TransparentStreamWriteRequestMessage request = (TransparentStreamWriteRequestMessage)transparentStreamMessageBase;
            Exception exception = null;

            try {
                baseStream.BeginWrite(request.Buffer, 0, request.Buffer.Length, (ar) => {
                    try {
                        baseStream.EndWrite(ar);
                    } catch (Exception ex) {
                        objectBusSession.SendMessage(new TransparentStreamWriteResponseMessage(streamID, request.ID, ex));
                    }
                }, request.Buffer);
            } catch (Exception ex) {
                exception = ex;
                objectBusSession.SendMessage(new TransparentStreamWriteResponseMessage(streamID, request.ID, exception));
            }
        }
Beispiel #5
0
        static StackObject *EndWrite_8(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.IAsyncResult @asyncResult = (System.IAsyncResult) typeof(System.IAsyncResult).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.IO.Stream instance_of_this_method = (System.IO.Stream) typeof(System.IO.Stream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.EndWrite(@asyncResult);

            return(__ret);
        }
Beispiel #6
0
        static int _m_EndWrite(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.Stream gen_to_be_invoked = (System.IO.Stream)translator.FastGetCSObj(L, 1);



                {
                    System.IAsyncResult _asyncResult = (System.IAsyncResult)translator.GetObject(L, 2, typeof(System.IAsyncResult));

                    gen_to_be_invoked.EndWrite(
                        _asyncResult);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Beispiel #7
0
 public WriteTransaction(System.IO.Stream s, byte[] dest, int off, int len)
     : base(true, new System.AsyncCallback((iar) => s.BeginWrite(dest, off, len, new System.AsyncCallback((ia) => s.EndWrite(ia)), null)), null, null)
 {
 }
Beispiel #8
0
 /// <inheritdoc/>
 public override void EndWrite(IAsyncResult asyncResult)
 {
     _underlyingStream.EndWrite(asyncResult);
 }
Beispiel #9
0
 /// <summary>
 /// Transfers an entire source stream to a target
 /// </summary>
 /// <param name="source">
 /// The stream to read
 /// </param>
 /// <param name="target">
 /// The stream to write
 /// </param>
 /// <returns>
 /// The total number of bytes transferred
 /// </returns>
 public Int32 Copy(Stream source, Stream target)
 {
     var copied = 0;
      var bufferIdx = 0;
      // start an initial dummy write to avoid
      // a null test within the copy loop
      var writer = target.BeginWrite(this.buffers[1], 0, 0, null, null);
      for (; ; )
      {
     // read into the current buffer
     var buffer = this.buffers[bufferIdx];
     var reader = source.BeginRead(buffer, 0, buffer.Length, null, null);
     // complete the previous write and the current read
     target.EndWrite(writer);
     var read = source.EndRead(reader);
     if (read == 0)
        break;
     copied += read;
     // start the next write for the completed read
     writer = target.BeginWrite(buffer, 0, read, null, null);
     // swap the buffer index for the next read
     bufferIdx = (bufferIdx + 1) % 2;
      }
      return copied;
 }
Beispiel #10
0
 /// <summary>
 /// Finaliza a escrita assincrona.
 /// </summary>
 /// <param name="asyncResult"></param>
 public override void EndWrite(IAsyncResult asyncResult)
 {
     _stream.EndWrite(asyncResult);
 }