コード例 #1
0
        public void sendMsgToAllClients(messageToEveryone msg)
        {
            try
            {
                dataTypes objToSend = new dataTypes();

                objToSend.setType(typeof(messageToEveryone).ToString());
                objToSend.setObject(msg);

                IFormatter formatter = new BinaryFormatter();
                Stream stream = new MemoryStream();

                formatter.Serialize(stream, objToSend);

                byte[] buffer = ((MemoryStream)stream).ToArray();

                for (int index = 0; index < netServ.clients.Count; index++)
                    netServ.clients[index].getSocket().Send(buffer, buffer.Length, 0);

                stream.Close();
            }
            catch (Exception ex)
            {
                netServ.serverMW.appendDebugOutput(ex.Message);
            }
        }
コード例 #2
0
ファイル: ClientMW.cs プロジェクト: ady2pak/licenta-2012
        private void sendBTN_Click(object sender, EventArgs e)
        {
            messageToEveryone msg = new messageToEveryone();

            msg.setMessage(msgBox.Text.Trim());
            msg.setMe(username);

            dataTypes objToSend = new dataTypes();

            objToSend.setType(typeof(messageToEveryone).ToString());
            objToSend.setObject(msg);

            IFormatter formatter = new BinaryFormatter();
            Stream stream = new MemoryStream();

            formatter.Serialize(stream, objToSend);

            byte[] buffer = ((MemoryStream)stream).ToArray();

            netServ.m_clientSocket.Send(buffer, buffer.Length, 0);

            stream.Close();

            msgBox.Clear();
        }