Hello.
I wnat to read some data from server, I'm using following code:
----------------------------------------------------------------------------------------
TcpClient cl = new TcpClient();
cl.Connect("SomeHost", 9000);
NetworkStream networkStream = cl.GetStream();
if (!networkStream.CanRead)
return;
byte[] myReadBuffer = new byte[1024];
String myCompleteMessage = "";
int numberOfBytesRead = 0;
do
{
numberOfBytesRead = networkStream.Read(myReadBuffer, 0,
myReadBuffer.Length);
myCompleteMessage = String.Concat(myCompleteMessage,
Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
}
while(networkStream.DataAvailable);
cl.Close();
----------------------------------------------------------------------------------------
When it executes lone:
numberOfBytesRead = networkStream.Read(myReadBuffer, 0,
myReadBuffer.Length);
The applications just heng up:(
What I'm doing wrong?
Thank you. 2 3430
David Dvali wrote: Hello. I wnat to read some data from server, I'm using following code: ---------------------------------------------------------------------------------------- TcpClient cl = new TcpClient(); cl.Connect("SomeHost", 9000);
NetworkStream networkStream = cl.GetStream();
if (!networkStream.CanRead) return; byte[] myReadBuffer = new byte[1024]; String myCompleteMessage = ""; int numberOfBytesRead = 0;
do { numberOfBytesRead = networkStream.Read(myReadBuffer, 0, myReadBuffer.Length); myCompleteMessage = String.Concat(myCompleteMessage, Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead)); } while(networkStream.DataAvailable);
cl.Close(); ---------------------------------------------------------------------------------------- When it executes lone: numberOfBytesRead = networkStream.Read(myReadBuffer, 0, myReadBuffer.Length); The applications just heng up:( What I'm doing wrong?
Thank you.
Because it's trying to read something which is not available.
TCPClinet has a property called ReceiveTimeout which Gets or sets the
amount of time a TcpClient will wait to receive data once a read
operation is initiated.
HTH
Can you tell me how can I use unblocked sockets?
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:uU**************@TK2MSFTNGP09.phx.gbl... David Dvali wrote: Hello. I wnat to read some data from server, I'm using following code: ---------------------------------------------------------------------------------------- TcpClient cl = new TcpClient(); cl.Connect("SomeHost", 9000);
NetworkStream networkStream = cl.GetStream();
if (!networkStream.CanRead) return; byte[] myReadBuffer = new byte[1024]; String myCompleteMessage = ""; int numberOfBytesRead = 0;
do { numberOfBytesRead = networkStream.Read(myReadBuffer, 0, myReadBuffer.Length); myCompleteMessage = String.Concat(myCompleteMessage, Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead)); } while(networkStream.DataAvailable);
cl.Close(); ---------------------------------------------------------------------------------------- When it executes lone: numberOfBytesRead = networkStream.Read(myReadBuffer, 0, myReadBuffer.Length); The applications just heng up:( What I'm doing wrong?
Thank you. Because it's trying to read something which is not available.
TCPClinet has a property called ReceiveTimeout which Gets or sets the amount of time a TcpClient will wait to receive data once a read operation is initiated.
HTH This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: MuZZy |
last post by:
HI,
How do i get a remote TcpClient address here?
// =======================================
TcpListener l = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080);
TcpListener.Start();
While...
|
by: jin |
last post by:
hi, i'm trying using the tcpClient to get a html file from net, instead of
using WebClient or WebRequest,
the main part of the source code is like this:
private void tcpconnect()
{
tcp=new...
|
by: Kirk |
last post by:
Hello,
I'm trying to get the current date/time from a (S)NTP server. It works
with UdpClient class, but not with TcpClient class. I want to use
TcpClient because i can set timeout values for...
|
by: Torsten Brasch |
last post by:
Hi All and Happy New Year ;)
I have a very strange problem with System.Net.Sockets.TcpClient().
For some reason, the number of bytes I can receive is limited to 5460 bytes.
I made sure that the...
|
by: Jerry Spence1 |
last post by:
I'm having a problem with the following excerpt:
dim tcpCli As New TcpClient
Dim ns As NetworkStream = tcpCli.GetStream
Dim sw As New StreamWriter(ns, System.Text.Encoding.Default)
Dim sr...
|
by: DrZoop |
last post by:
Long story short: I am misusing the TCPClient class. I am sending
400-500 byte messages, and data is being lost.
How can the TCPClient class be misused to lose data?
Background notes:
-I know...
|
by: Andrew Jackson |
last post by:
I am writing a newsgroup client. I have the protocol figured out. But I
get slow transfer speeds off any of the network objects read the data from
For example one of the commands for a news...
|
by: Zytan |
last post by:
I just had the problem occur again, with NetworkStream.Write() doing
its thing with a timeout... and it just sits and waits and waits and
waits... it never times outs. So, I shut the server down...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |