Пример #1
0
        /**
         * 客户端发送消息
         */
        public void send2Server(MsgData md)
        {
            String mdString = MsgData.SerializeMsg(md);

            streamW.WriteLine(mdString);
            streamW.Flush();
        }
Пример #2
0
        /**
         * 发送信息给在线客户端
         * 返回 List<string> failedList
         */
        public List <string> sendMsg2SockeList(String msg, List <String> target)
        {
            List <string> failedList = new List <string>();

            foreach (String ipAndPort in target)
            {
                MsgData md = new MsgData();
                md.msg  = msg;
                md.type = "TEXT";
                string mdString = MsgData.SerializeMsg(md);

                string error = this.sendMsg(mdString, ipAndPort);
                if (error.Length > 0)
                {
                    failedList.Add(error);
                }
            }
            return(failedList);
        }
Пример #3
0
        /**
         * 传文件
         */
        public void translateFile_simple(String ipAndPort, String fileFullPath)
        {
            string filename = System.IO.Path.GetFileName(fileFullPath);

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileFullPath);
            long fileSize = fileInfo.Length;

            MsgData md = new MsgData();

            md.type     = "FILE";
            md.fileName = filename;
            md.fileSize = fileSize;
            md.msg      = FileTranser.getFileContent(fileFullPath);
            String mdString = MsgData.SerializeMsg(md);

            String error = alive_list.sendMsg(mdString, ipAndPort);

            if (error.Length > 0)
            {
                appendToHistory("文件传输异常:" + error + "\n");
                return;
            }
        }