473,804 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NetworkStream Write Not Failing

I have a TCP server to which a number of mobile devices connect. If a device
disconnects(mos tly no clean close as they usually lose cell coverage or
shutdown), and the server then tries to send data using the
Networkstream.W rite method, its NOT throwing an exception. I am using the
TCPClient class.
I am able to reproduce this by shutting down my test device(turning off
power) and then sending some data. The Write just finishes as if the data
was sent.
Is there some timeout that has to occur before the Write fails ?

Thanks

Srinivas
Nov 17 '05 #1
2 2406
Are you using a NetworkStream to write? If so, just check the CanWrite property

TcpClient tcp = new TcpClient("www. google.com", 80)
NetworkStream ns = new NetworkStream(t cp, true)
if (ns.CanWrite

ns.Write(myByte s, 0, 256)

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 17 '05 #2
Thanks for the reply.
Yes I am using the NetworkStream. Even the CanWrite returns true. Here is
part of the code that writes

if (Cmd != "")
{
try
{
byte[] OTA = Encoding.ASCII. GetBytes(Cmd);
try
{
if(_NetworkStre am.DataAvailabl e)
{
//JUst to check for connection
}
}
catch (SocketExceptio n) //remote closed
{
this.CloseSocke t();
return;
}
if(_NetworkStre am.CanWrite)
{
_NetworkStream. Write(OTA,0,(in t)OTA.Length);
}
}
catch(Exception eOTA)
{
Controller.EMai lErr("OTA Send Error",eOTA.Mes sage.ToString() );
}
}
The mobile unit is a third party device and I just power it down to simulate
a lost TCP connection.
I even used DataAvailable as it is supposed to throw an exception if remote
disconnects. Even after I shutdown the remote device, the CanWrite returns
true and the Write does not thrown an exception.
The mobile unit connects using a wireless cellular network(ATT/cingular) -
would that have something to do with it ?

Thanks again
"AstroDrabb " <AstroDrabb@-NOSPAM-yahoo.com> wrote in message
news:uy******** ******@TK2MSFTN GP09.phx.gbl...
Are you using a NetworkStream to write? If so, just check the CanWrite
property.

TcpClient tcp = new TcpClient("www. google.com", 80);
NetworkStream ns = new NetworkStream(t cp, true);
if (ns.CanWrite)
{
ns.Write(myByte s, 0, 256);
}
---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

Nov 17 '05 #3

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

Similar topics

1
556
by: cmjman | last post by:
I have an issue where networkStream.Write doesn't perform its write downstream from my client program until the network stream is closed. I then see the data that was sent appear on the other side. I am sending a small amound of data and read where data wasn't sent until the buffer reached a larger size. However, there is a TcpClient property call NoDelay that is suppose to eliminate this delay. Here is a snippet of my code below. Can...
1
4785
by: Casey Watson | last post by:
Hi :) I'm having some major trouble with an XML Client/Server application that I am writing. I am using NetworkStream with CryptoStream to Read and Write XML between computers. Now, whenever I write the XML, the Server section which uses the XMLTextReader Class will not accept EndElements period, and neither the ReadStartElement or ReadEndElement will work properly. However, if I only send to WriteStartElements over the network, the...
1
2655
by: kmacintyre | last post by:
I am trying to us a simple NetworkStream to transfer a file over tcp. This works most of the time, but one specific file never downloads(.mdb file). It seems to close the socket and I get an "unable to write data to transport connection" error. I have tried multiple ways to transfer this file(including remoting, sockets without network stream) and downloaded different examples of client/server byte transfer, all with the same result....
10
3956
by: Sven Huijbrechts | last post by:
Hello, I need to send a couple of "NUL"s -> HEX value "00" on a networkstream.. This is the code we currently use to send string: Dim sendBytes As () = Encoding.ASCII.GetBytes(inputtext.ToString) networkStream.Write(sendBytes, 0, sendBytes.Length) Since there is no char value for hex 00 (NUL) it's not possible to use a
7
5189
by: david.topham | last post by:
Hi The code below demostrates an issue I'm having with with NetworkStream: using System; using System.Net.Sockets; namespace TCPCTest { class Class1
5
4220
by: | last post by:
I've got a basic "chat" infrastructure that can send objects across the wire, but I'm running into a few issues with trying to send multiple messages and things behaving differently in debug and release... Is there anyone out there that considers themselves a threading / sockets / serialization guru? Not sure if it's appropriate to post an entire project here and the issues discussion is probably a bit too complex for newsgroup back and...
3
11044
by: shahla.saeed | last post by:
hi, plzz check my code and let me know where the problem is lying...becuase whenever i try to tansfer the file of 573KB(mp3) it just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time i run the program).....but when i watch the transfering of bytes by debuging it.(RED dot on while(nfs.CanRead) )..it shows that complete bytes are transfered.(in my case i-e 573Kb)....i am unable to understand whats going wrong in my program....
7
4277
by: littleIO | last post by:
Hi, I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated. I have a server which listens, receives calls, processes them and sends back the results to clients. The code below makes the client application not to respond. Client can send data but is stuck in the process of waiting information back from the server. Any ideas?
1
4460
by: Almund | last post by:
Hi, I'm trying to implement streaming over http and got stuck with a problem trying to send chunks of data using the .Net NetworkStream object. All works fine as long as I send the entire data in one invocation to the NetworkStream, like: _stream.Write(buffer, 0, buffer.Length) But if i try:
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.