By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,899 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,899 IT Pros & Developers. It's quick & easy.

Socket Help

P: n/a
I am connecting to a remote host and am able to write to
the network stream, but I can't read from it. When I
validate if there is any DataAvailable to read, it always
comes back false. Below is the code, can someone please
tell me why I'm not able to read any responses? Thanks!
TcpClient = new TcpClient();
client.Connect( System.Net.IPAddress.Parse( ipString ),
portInt ); // ipString and portInt are set in code above
byte[] data = System.Text.Encoding.ASCII.GetBytes(
toWriteString); // toWriteString set in code above
NetworkStream stream = client.GetStream();
if ( stream.CanWrite )
stream.Write( data, 0, data.Length);
data = new byte[client.ReceiveBufferSize];
string responseData = String.Empty;
if ( stream.DataAvailable && stream.CanRead )
{
stream.Read( data, 0, client.ReceiveBufferSize );
responseData = System.Text.Encoding.ASCII.GetString(
data );
}
What am I doing wrong???
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.