public static RemoteFunction <TInput> BindNew(RemoteClient client, string name, string proto = "") { RemoteFunction <TInput> function = new RemoteFunction <TInput>(); if (function.Bind(client, name, proto)) { return(function); } return(null); }
public bool Connect(string server = "localhost", int port = -1) { Debug.Assert(!_active); if (port <= 0) { port = GetDefaultPort(); } Socket = ConnectSocket(server, port); if (Socket == null) { DefaultOutput.PrintErr("Could not connect to %s:%d\n", server, port); return(false); } _active = true; var headerList = new List <byte>(); headerList.AddRange(Encoding.ASCII.GetBytes(RpcHandshakeHeader.RequestMagic)); headerList.AddRange(BitConverter.GetBytes(1)); byte[] header = headerList.ToArray(); if (Socket.Send(header) != header.Length) { DefaultOutput.PrintErr("Could not send handshake header.\n"); Socket.Close(); Socket = null; return(_active = false); } if (!ReadFullBuffer(Socket, header, header.Length)) { DefaultOutput.PrintErr("Could not read handshake header.\n"); Socket.Close(); Socket = null; return(_active = false); } if (!PartialArrayCompare(header, Encoding.ASCII.GetBytes(RpcHandshakeHeader.ResponseMagic)) || BitConverter.ToInt32(header, Encoding.ASCII.GetBytes(RpcHandshakeHeader.ResponseMagic).Length) != 1) { DefaultOutput.PrintErr("Invalid handshake response: %s.\n", Encoding.Default.GetString(header)); Socket.Close(); Socket = null; return(_active = false); } if (_bindCall == null) { _bindCall = new RemoteFunction <CoreBindRequest, CoreBindReply>(); } _bindCall.Name = "BindMethod"; _bindCall.PClient = this; _bindCall.Id = 0; if (_runcmdCall == null) { _runcmdCall = new RemoteFunction <CoreRunCommandRequest>(); } _runcmdCall.Name = "RunCommand"; _runcmdCall.PClient = this; _runcmdCall.Id = 1; return(true); }
public bool connect(int port = -1) { Debug.Assert(!active); if (port <= 0) { port = GetDefaultPort(); } socket = ConnectSocket("localhost", port); if (socket == null) { default_output().printerr("Could not connect to localhost: %d\n", port); return(false); } active = true; List <byte> headerList = new List <byte>(); headerList.AddRange(Encoding.ASCII.GetBytes(RPCHandshakeHeader.REQUEST_MAGIC)); headerList.AddRange(BitConverter.GetBytes((Int32)1)); byte[] header = headerList.ToArray(); if (socket.Send(header) != header.Length) { default_output().printerr("Could not send handshake header.\n"); socket.Close(); socket = null; return(active = false); } if (!readFullBuffer(socket, header, header.Length)) { default_output().printerr("Could not read handshake header.\n"); socket.Close(); socket = null; return(active = false); } if (!partialArrayCompare(header, Encoding.ASCII.GetBytes(RPCHandshakeHeader.RESPONSE_MAGIC)) || BitConverter.ToInt32(header, Encoding.ASCII.GetBytes(RPCHandshakeHeader.RESPONSE_MAGIC).Length) != 1) { default_output().printerr("Invalid handshake response: %s.\n", System.Text.Encoding.Default.GetString(header)); socket.Close(); socket = null; return(active = false); } if (bind_call == null) { bind_call = new RemoteFunction <CoreBindRequest, CoreBindReply>(); } bind_call.name = "BindMethod"; bind_call.p_client = this; bind_call.id = 0; if (runcmd_call == null) { runcmd_call = new RemoteFunction <CoreRunCommandRequest>(); } runcmd_call.name = "RunCommand"; runcmd_call.p_client = this; runcmd_call.id = 1; return(true); }
public TimedRemoteFunction(float interval, RemoteFunction <TInput, TOutput> function) { this.function = function; this.interval = interval; }