multithreading - TCP/IP Multithreading Application
问题描述
I have an Server/Client application and just wanted to address some concerns I have.
It uses TCP/IP sockets to communicate with each other.
My concerns is the following...
I have a section of code that handles a series of commands from the client (this multi-threads for EVERY user that is connected) this can have up to 20-40-60 threads.
I have dedicated thread to handle live chats for users online.
I have another dedicated thread that handles push notifications to the client.
My question is... am I really doing it properly?
I am concerned that if a push notificaiton/chat/client command is processed at the same time, the client will receive the data incorrectly.
In a nutshell (of course hypothetically speaking):
Client Sends Command: "Get-Me-Data"
Push Notification sends to same client: "You_Got_Mail"
Chat Notification sends to same client: "MESSAGE"
I am concerned that client will receieve the data in this manner Get-Me-MESSAGE-Mail-Data-Got
I heard of using SyncLock to prevent this, should I syncLock the client NetworkStream?
Thanks in advance.
解决方案
推荐阅读
- r - 运行应用程序时出现闪亮错误:match.arg(position) 中的错误:'arg' 必须为 NULL 或字符向量
- r - 如何提高 Rstudio 中导出的 ggsurvplot 图像的分辨率
- sql - 取最后一个变化值
- javascript - Node.js 将 Buffer 转换为对象/函数
- oracle - 比较 oracle apex 中的时间戳时,调用“<=”时参数的数量或类型错误
- google-apps-script - 在两个不同的函数中使用两个子字符串时,“TypeError:无法读取未定义的属性‘子字符串’”
- javascript - 使用 Flexbox 将内联 ul 彼此相邻包装
- vba - 粗体字符串中的详细信息
- java - 检查 startTime 和 endTimer 是否在两次之间
- elasticsearch - 有没有办法用一个查询创建多个 ElasticSearch 索引