ShootManiaXMLRPC.XmlRpc.XmlRpc.ReceiveCall C# (CSharp) Méthode

ReceiveCall() public static méthode

public static ReceiveCall ( Socket in_socket, byte inHeader ) : GbxCall
in_socket System.Net.Sockets.Socket
inHeader byte
Résultat GbxCall
        public static GbxCall ReceiveCall(Socket in_socket, byte[] inHeader)
        {
            if (in_socket.Connected)
            {
                lock (in_socket)
                {
                    // read response size and handle ...
                    byte[] bSize = new byte[4];
                    byte[] bHandle = new byte[4];
                    if (inHeader == null)
                    {
                        in_socket.Receive(bSize);
                        in_socket.Receive(bHandle);
                    }
                    else
                    {
                        Array.Copy(inHeader, 0, bSize, 0, 4);
                        Array.Copy(inHeader, 4, bHandle, 0, 4);
                    }
                    int size = BitConverter.ToInt32(bSize, 0);
                    int handle = BitConverter.ToInt32(bHandle, 0);

                    // receive response body ...
                    byte[] data = ReceiveRpc(in_socket, size);

                    // parse the response ...
                    GbxCall call = new GbxCall(handle, data);

                    return call;
                }
            }
            else
            {
                throw new NotConnectedException();
            }
        }

Usage Example

Exemple #1
0
        private void OnDataArrive(IAsyncResult iar)
        {
            // end receiving and check if connection's still alive ...
            try
            {
                tcpSocket.EndReceive(iar);

                // receive the message from the server ...
                GbxCall call = XmlRpc.ReceiveCall(this.tcpSocket, m_buffer);

                // watch out for the next calls ...
                m_buffer    = new byte[8];
                asyncResult = tcpSocket.BeginReceive(m_buffer, 0, m_buffer.Length, SocketFlags.None, new AsyncCallback(OnDataArrive), null);

                if (call.Type == MessageTypes.Callback)
                {
                    // throw new event ...
                    GbxCallbackEventArgs eArgs = new GbxCallbackEventArgs(call);
                    OnGbxCallback(eArgs);
                }
                else
                {
                    // add the response to the queue ...
                    lock (this)
                    {
                        responses.Add(call.Handle, call);
                    }

                    // callback if any method was set ...
                    if (callbackList[call.Handle] != null)
                    {
                        ((GbxCallCallbackHandler)callbackList[call.Handle]).BeginInvoke(call, null, null);
                        callbackList.Remove(call.Handle);
                    }
                }
            }
            catch
            {
                this.m_connected = false;

                // something went wrong :S
                tcpSocket.Close();

                // release a disconnect event ...
                OnDisconnectCallback();
            }
            finally
            {
                // we received something :)
                callRead.Set();
            }
        }