Ejemplo n.º 1
0
 public static void PrintMessage(PRSMessage msg)
 {
     Console.WriteLine("Message type:" + msg.msgType);
     Console.WriteLine("Status:" + msg.status);
     Console.WriteLine("Port" + msg.port);
     Console.WriteLine("Service:" + msg.serviceName + "\n");
 }
Ejemplo n.º 2
0
        //Static Make Methods
        public static PRSMessage MakeSTOP()
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType = MsgType.STOP;
            return(msg);
        }
Ejemplo n.º 3
0
        public static void SendMessage(Socket sock, IPEndPoint endPt, PRSMessage msg)
        {
            Console.WriteLine("Sending message to server...");
            byte[] buffer = msg.Serialize();
            int    result = sock.SendTo(buffer, endPt);

            Console.WriteLine("Sent " + result.ToString() + " bytes: " + new string(ASCIIEncoding.UTF8.GetChars(buffer)));
        }
Ejemplo n.º 4
0
        public static PRSMessage MakeLOOKUP_PORT(string serviceName)//Sends a message of service name
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType     = MsgType.LOOKUP_PORT;
            msg.serviceName = serviceName;
            return(msg);
        }
Ejemplo n.º 5
0
        public static PRSMessage MakePORT_DEAD(ushort port)
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType = MsgType.PORT_DEAD;
            msg.port    = port;
            return(msg);
        }
Ejemplo n.º 6
0
        public static PRSMessage MakeRESPONSE(Status response, ushort port)//response to
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType = MsgType.RESPONSE;
            msg.status  = response;
            return(msg);
        }
Ejemplo n.º 7
0
        public static PRSMessage MakeREQUEST_PORT(string serviceName)
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType     = MsgType.REQUEST_PORT;
            msg.serviceName = serviceName;
            return(msg);
        }
Ejemplo n.º 8
0
        public static PRSMessage MakeKEEP_ALIVE(string serviceName, ushort port)
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType     = MsgType.KEEP_ALIVE;
            msg.serviceName = serviceName;
            msg.port        = port;
            return(msg);
        }
Ejemplo n.º 9
0
        public static PRSMessage MakeCLOSE_PORT(string serviceName, ushort port)
        {
            PRSMessage msg = new PRSMessage();

            msg.msgType     = MsgType.CLOSE_PORT;
            msg.serviceName = serviceName;
            msg.port        = port;
            return(msg);
        }
Ejemplo n.º 10
0
        public static PRSMessage Deserialize(byte[] buffer)
        {
            PRSMessage MSG = new PRSMessage();

            MSG.msgType     = (PRSMessage.MsgType)buffer[0];
            MSG.serviceName = new string(ASCIIEncoding.UTF8.GetChars(buffer, SERVICE_LOCATION, 49));
            MSG.port        = BitConverter.ToUInt16(buffer, PORT_LOCATION);
            MSG.status      = (PRSMessage.Status)buffer[STATUS_LOCATION];
            MSG.port        = (ushort)IPAddress.NetworkToHostOrder(MSG.port);
            return(MSG);
            //turn bytes into integral values
        }
Ejemplo n.º 11
0
        public static PRSMessage ReceiveMessage(Socket sock, ref IPEndPoint remoteIPEP)
        {
            Console.WriteLine("Waiting for message from client...");
            byte[]   buffer   = new byte[PRSMessage.SIZE];
            EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
            int      result   = sock.ReceiveFrom(buffer, ref remoteEP);

            remoteIPEP = (IPEndPoint)remoteEP;
            //Console.WriteLine("Received " + result.ToString() + " bytes: " + new string(ASCIIEncoding.UTF8.GetChars(buffer)));
            // deserialize and handle the message
            PRSMessage msg = PRSMessage.Deserialize(buffer);

            return(msg);
        }