简体   繁体   中英

multiple tcpip clients connected to same server?

I'm just starting out learning about TCP/IP.

I have written a simple TCP/IP server which listens on port 3000 and spawns a thread when a connection is received. That new thread sits and reads data. My client application creates 100 connections to this server, and, using the tread pool, each connection gets a chance to send a unique message to the server.

The server doesn't respond to the message - it only prints it to the screen. So, the thing I am seeing is the listening thread in the server will sometimes read messages from several different clients in the same read.

I was under the impression that TCP would separate each message to allow each thread in the server to read the message sent to it, not to all others as well. Am I mistaken in my understanding, or do I have something else going on in my code?

You have something else in your code. Neither TCP or UDP will receive from multiple clients in the same read.

I would take a look at my buffer handling. Do post some server code regarding the reads.

Thanks. I figured it out. My client threads were executing much more often than I the read threads on the server. As a result, each read often contained the data from multiple writes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM