0

I am trying to write/read to sslstream on 443 port.

I can able write data to that sslstream but while reading from that sslstream,​ it is waiting to read, forever.

Sample code:

 var add= "IPGoesHere";

 var port = 443;

var remoteIpAdd= IPaddress.
Parse("IPGoesHere");

var socket = new Socket(remoteIpAdd.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

socket.Connect(new IPEndPoint(remoteIpAdd,port));

var netstream = new NetworkStream(
socket);

var sslstream = new SslStream(
netstream, false, callback1, 
callback2);

sslstream.AuthenticateAsClient
(add,null, SslProtocols.Tls12, false);

var bytes = Encoding.Ascii.GetBytes("something");

sslstream.write( bytes,0,bytes.Length);
sslstream.Flush();

sslstream.Read(new byte[9],0,9);  //Here it is waiting indefinitely..

Callback1 is a RemoteCertificateValidationCallback method and I am returning true here.

Callback2 is a Local certificate selection callback method and returning null here.

I am thinking like, how it can not able to read when it can able to write.

Could someone share some input on this issue.

PS: I typed entire code in mobile app. Regret for alignment.

NANDAKUMAR THANGAVELU
  • 611
  • 3
  • 15
  • 34
  • If it's waiting it means it hasn't received anything from the server. What do you expect to receive? What kind of server are you connecting to? If it's a webserver, you'll need to send a valid HTTP request (or at least include `"\r\n\r\n"` in your request to force it to respond with an error). – C.Evenhuis Aug 17 '17 at 14:21
  • @evenhuis: In previous line I have written something. And I am trying to read the data which is written. Am I understanding something wrong? Could u advise. Thx. – NANDAKUMAR THANGAVELU Aug 17 '17 at 14:27
  • You're connecting to a computer (`remoteIpAdd`) - writing data means sending data to that computer, and reading data means receiving data from that computer. Why would you connect to another computer just to read your _own_ data? – C.Evenhuis Aug 17 '17 at 14:31
  • @evenhuis: it is a load balancer. We are trying to have app behind this load balancer which will communicate through this port. We are checking whether we can send/receive data from that port. So, just trying to send and receive data from my ip itself. – NANDAKUMAR THANGAVELU Aug 17 '17 at 14:40
  • Okay. Just keep in mind you can only _receive_ data that is sent _to_ you. You won't receive data sent _by_ you (even if you were sending to "localhost", you wouldn't receive the data on the same `Socket`). – C.Evenhuis Aug 17 '17 at 14:52

0 Answers0