Send() public static method

Sends a single object over the specified stream
public static Send ( NetworkStream stream, object obj ) : void
stream System.Net.Sockets.NetworkStream Stream to send the message over
obj object Object to send
return void
Example #1
0
        /// <summary>
        /// Sends a BBRequest to the server
        /// </summary>
        /// <param name="request">The BBRequest to send</param>
        /// <returns>If the reqeuest expects a response, returns the response</returns>
        public BBResponse SendRequest(BBRequest request)
        {
            object reply;

            using (TcpClient client = new TcpClient()) {
                client.Connect(serverEndPoint);
                NetworkStream networkStream = client.GetStream();

                Message.Send(networkStream, request);
                reply = Message.Recieve(networkStream);
            }

            if (reply == null)
            {
                throw new Exception("BBRequest Error: Expected reply but recieved none");                //Console.Error.WriteLine("BBRequest Error: Expected reply but recieved none");
            }
            else
            {
                return(reply as BBResponse);
            }
        }