Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Why does the unable to read data from the transport connection error occur?
Next
Answered
Oscar O'Brien
  • 10
Oscar O'Brien
Asked: May 18, 20222022-05-18T15:51:18+00:00 2022-05-18T15:51:18+00:00In: csharp

Why does the unable to read data from the transport connection error occur?

  • 10

. Advertisement .

..3..

. Advertisement .

..4..

I don’t know what I’m doing wrong, but I’ve already lost a couple of days struggling with this. Here is my command line:

tcpClient = (TcpClient)client;
 clientStream = tcpClient.GetStream();
 sr = new StreamReader(clientStream);
 sw = new StreamWriter(clientStream);
 
 // line 96: 
 a = sr.ReadLine();

This returns:

Couldn't get stream from client or login failed: System.IO.IOException:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

I don’t have any experience with the “unable to read data from the transport connection.” In this case, how should I change?

unable to read data
  • 2 2 Answers
  • 106 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    hdtutoria Expert
    2022-06-09T12:41:35+00:00Added an answer on June 9, 2022 at 12:41 pm

    The cause: This error typically indicates that the target machine is running, but the service you’re trying to connect to isn’t. (It either came to a halt, crashed, or is preoccupied with another request.)

    The solution: The issue was rectified by adding the following line before making the call:

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    • 13
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Léo Gauthier
    2022-05-26T03:55:30+00:00Added an answer on May 26, 2022 at 3:55 am

    This error occurred when I called a web-service. This issue also had to do with transport level security. Although I could call the web service through a website project it would not work if I used the same code in a test program. I would then get this message as a WebException. The issue was resolved by adding the following line before calling the web-service:

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


    Edit

    System.Net.ServicePointManager.SecurityProtocol – This property
    selects the version of the Secure Sockets Layer (SSL) or Transport
    Layer Security (TLS) protocol to use for new connections that use the
    Secure Hypertext Transfer Protocol (HTTPS) scheme only; existing
    connections are not changed.

    When selecting the protocol version, I think the SecurityProtocol configuration should be considered.

    TLS handshake – This protocol is used to exchange all the information required by both sides for the exchange of the actual application data by TLS.

    ClientHello – A client sends a ClientHello message specifying the highest TLS protocol version it supports …

    ServerHello – The server responds with a ServerHello message, containing the chosen protocol version … The chosen protocol version should be the highest that both the client and server support. For example, if the client supports TLS version 1.1 and the server supports version 1.2, version 1.1 should be selected; version 1.2 should not be selected.

    • 15
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.