473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

why TcpClient.GetStream(), not just a property? Will exception go away next time?

Hi,

Why TcpClient has a method TcpClient.GetStream(), not just a read only
property?

By implementing it as a method, does that mean, each time GetStream() could
return a different stream? In other words, is that safe I only call
GetStream() once and set it to a class' variable and reuse it later?

And sometime I see TcpClient.GetStream() throws
System.InvalidOperationException: Operation not allowed on non-connected
sockets. Then I will force the user to log out.

Now I wonder is this "temporary" exception? Maybe

1: I save the stream in class variable, next time I just call Read and
wirte method, do not call GetStream() first, the exception will not occure.

2: If I catch this exception, ignore it, next time, GetStream() or
ReadByte(),Write() will work just fine.

Can someone tell if my guess right or not? It is difficult to test, since
this exception will not always occure.

Thanks,
Ryan
Jun 9 '06 #1
1 3053
Hi,

"Ryan Liu" <ad********@online.sh.cn> wrote in message
news:uI**************@TK2MSFTNGP04.phx.gbl...
Hi,

Why TcpClient has a method TcpClient.GetStream(), not just a read only
property?
Frankly I have no a precise answer for this.
By implementing it as a method, does that mean, each time GetStream()
could
return a different stream? In other words, is that safe I only call
GetStream() once and set it to a class' variable and reuse it later?
No, it will ALWAYS return the same stream, or exception if Connect was not
called before.
And sometime I see TcpClient.GetStream() throws
System.InvalidOperationException: Operation not allowed on non-connected
sockets. Then I will force the user to log out.

Now I wonder is this "temporary" exception? Maybe


The TcpClient is not connected to a remote location.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Theo | last post by:
Hi, I am using a tcpclient and a tcplistener to send and receive packets. The client sends a packet and the listener replies with another one. I can send 2 packets and get an answer from the...
3
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok...
0
by: Hawk Wu via DotNetMonster.com | last post by:
Hello, I have odd problem. When I close my application wait around 5 minute. The pocket of screen will show one message "System.Net.Sockets.Tcpclient" of message box. My source code as below. ...
2
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
3
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work...
2
by: David Dvali | last post by:
Hello. I wnat to read some data from server, I'm using following code: ---------------------------------------------------------------------------------------- TcpClient cl = new TcpClient();...
1
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client...
1
by: WildBill | last post by:
I am using a tcpclient and a network stream to communicate with the TCP port on a printer for testing the printer firmware. The code I have works perfectly the first time I run it. The printer...
0
by: sternr | last post by:
Hey, I'm using a TcpClient to create HTTP requests to my web-server (I know of HttpWebRequest, it is mandatory for me to use TcpClient.). Here's my code: TcpClient tcp = new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.