Exemple #1
0
 internal static void SendControlByte(Stream s, NetServerControl controlByte)
 {
     if (s == null)
     {
         throw new ArgumentNullException();
     }
     s.WriteByte((byte)controlByte);
     Trace.TraceInformation("Sent control byte: " + controlByte.ToString());
 }
Exemple #2
0
        internal static NetServerControl TryReceiveMessage <T>(Stream stream, TypeModel customDeserializer, out T message)
        {
            if (stream == null)
            {
                throw new ArgumentNullException();
            }
            message = default(T);
            while (true)
            {
                int b = stream.ReadByte();
                if (b < 0)
                {
                    Trace.TraceInformation("Reached end of stream");
                    return(NetServerControl.Close);
                }

                NetServerControl ca = (NetServerControl)b;
                if (ca == NetServerControl.KeepAliveNoRead)
                {
                    continue;
                }
                else if (ca == NetServerControl.MessageFollows)
                {
                    message = customDeserializer.NullSafe_Deserialize_Int32Prefix <T>(stream);
                    return(ca);
                }
                else if (ca == NetServerControl.Close)
                {
                    Trace.TraceInformation("Other end requested connection be closed gracefully");
                    return(ca);
                }
                else if (ca == NetServerControl.TerminateServer)
                {
                    Trace.TraceInformation("Other end requested server to terminate.");
                    return(ca);
                }
                else
                {
                    throw new IOException("Received invalid control byte recieved from other end");
                }
            }
        }
Exemple #3
0
 public void SendControlByte(NetServerControl controlByte)
 {
     SendControlByte(messageStream, controlByte);
 }