The same Socket instance cannot receive server data for the second time !! (Please forgive me for taking up the homepage temporarily. This problem has plagued me for two days)

Source: Internet
Author: User
Server:Two threads are created to process client requests. One thread is used to receive the connected Socket and add the Socket to a Queue object; another thread is used to propose the Socket in the Queue for receiving and sending operations. The receiving and sending operations are asynchronous.

Client:Create a NetworkStream instance (NetworkStream stream = new NetworkStream (Socket, true);) using a socket connected to the server, and package the NetworkStream instance into a System. IO. in the BufferedStream instance (/* used to receive */Stream inStream = new BufferedStream (stream);/* used to send */Stream outStream = new BufferedStream (stream );) send and receive data from the server.

Then I created a connection pool, initialized and created 10 server connections, and wrote a single-thread test program, extract the 10 connections from the connection pool to send and receive data in sequence. Everything is OK (the connection is returned to the connection pool ), but when I pull a connection from the connection pool again (10 created connections have been used up, this is the second connection, which has been used before) when sending and receiving data, the test program cannot receive the data returned by the server. (No matter on the client or server, I have not closed the connection after sending/receiving data)

From the log on the server side, the server receives the data sent from the client, and the server also successfully sends the data, but the client does not receive the data.

This problem has been plagued for the next two days ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.