private static GAISWriter HandleReader(GAISReader gr) { OPCODE op = (OPCODE)gr.ReadInt32(); switch (op) { case OPCODE.REGISTER: HandleRegister(gr); return(null); case OPCODE.REMOVE: HandleRemove(gr); return(null); case OPCODE.VIDEO_START: return(HandleVideoStart(gr)); case OPCODE.VIDEO_END: return(HandleVideoEnd(gr)); case OPCODE.VIDEO_UPDATE: return(HandleVideoUpdate(gr)); default: return(null); } }
private void startFirst() { while (!connected) { try { if (client.Available > 0) { gr = new GAISReader(client.GetStream()); Int32 id = gr.ReadInt32(); nickName = gr.ReadString(); foreach (ConnectionInfo c in Server.connections) { if (c.nickName == nickName) { GAISWriter gw = new GAISWriter(); gw.Write((Int32)OPCODE.RESPONSE); gw.Write((Int32)RESPONSE.NICKNAME_TAKEN); GAISWriter gwSend = new GAISWriter(client.GetStream()); gwSend.Write(gw.ToArray()); gwSend.Flush(); return; } } ConnectionInfo ci = new ConnectionInfo(); ci.nickName = nickName; ci.cl = client; Server.connections.Add(ci); //create a new thread for this user chatThread = new Thread(new ThreadStart(Run)); //start the thread chatThread.Start(); connected = true; } } catch { client.Close(); connected = true; } Thread.Sleep(100); } }
private static GAISWriter HandleVideoUpdate(GAISReader gr) { GAISWriter gw = new GAISWriter(); gw.Write((Int32)OPCODE.VIDEO_UPDATE); gw.Write(gr.ReadString()); Int32 size = gr.ReadInt32(); Byte[] arr = gr.ReadBytes(size); if (arr.Length > 0) { gw.Write(size); gw.Write(arr); return(gw); } return(null); }