public bool RemoteCall(string Method, byte[] Args) { UInt64 hash = FNV1a.Hash(Method); byte[] buf; int hedrlen; int argslen = Args == null ? 0 : Args.Length; buf = new byte[m_hedrsize + argslen]; hedrlen = NetStruct.PackFmtBuffer(buf, 0, "li", unchecked ((Int64)hash), argslen); if (hedrlen != m_hedrsize) { Console.WriteLine($"RemoteClient.RemoteCall() internal error"); return(false); } if (argslen > 0) { Array.Copy(Args, 0, buf, hedrlen, argslen); } m_calls.Add(buf); return(true); }
public RemoteClient(TcpClient Client, RemoteClass Klass) { m_tcp = Client; m_calls = new List <byte[]>(); m_class = Klass; m_hedrsize = NetStruct.FmtLen("li", (Int64)0, (int)0); }
public bool RemoteCall(string Method, string FmtArgs, params object[] Args) { byte[] args = null; if (FmtArgs != null && FmtArgs.Length > 0 && (args = NetStruct.PackFmt(FmtArgs, Args)) == null) { Console.WriteLine($"RemoteClient.RemoteCall() failed to pack args '{FmtArgs}'"); return(false); } return(RemoteCall(Method, args)); }
/// <summary> /// - Blocking call to receive and run the next command /// </summary> /// <returns> /// <see cref="RpcCode.Ok"/>: A call was received and executed /// <br><see cref="RpcCode.BadRemoteCall"/>: Bad data (Wrong protocol, calling unknown function)</br> /// <br><see cref="RpcCode.BadConnection"/>: Couldn't receive data. Socket was likely terminated</br> /// <br><see cref="RpcCode.InternalError"/>: Exception was thrown while receiving data</br> /// </returns> public RpcCode Recv() { RemoteMethod meth = null; UInt64 hash; int argslen; List <object> list; NetworkStream stream = m_tcp.GetStream(); byte[] buf = new byte[m_hedrsize]; try { if (!ReadBytes(buf, 0, buf.Length)) { Console.WriteLine("RemoteClient.Recv() couldn't receive arg header"); return(RpcCode.BadConnection); } if ((list = NetStruct.UnpackFmt(buf, 0, "li")) == null) { return(RpcCode.BadRemoteCall); } Int64 i64 = (Int64)list[0]; hash = unchecked ((UInt64)i64); argslen = (int)list[1]; if (argslen < 0) { return(RpcCode.BadRemoteCall); } meth = m_class.FindHash(hash); if (meth == null) { Console.WriteLine($"RemoteClient.Recv() failed to find function hash 0x{hash.ToString("X")}!"); return(RpcCode.BadRemoteCall); } buf = new byte[argslen]; if (argslen > 0 && !ReadBytes(buf, 0, buf.Length)) { Console.WriteLine("RemoteClient.Recv() failed to receive call args"); return(RpcCode.BadConnection); } } catch (Exception) { return(RpcCode.InternalError); } meth.Call(this, buf); return(RpcCode.Ok); }