473,396 Members | 1,858 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,396 software developers and data experts.

Stuck in stream.read ... plz help.

hi guys..
im writing an application that uses windows service to listen (as a
tcplistener) for any data sent (by a tcpclient) ...
one kind of the requests might be a file sent by client and the service
should recieve it as number of packets.
the problem is: in the windows service when it detects that the data
coming is a file it make a loop (which equals the number of packets the
client will send the file by it, which will be determined by the first
packet.)
BUT.. if the client (for some reason didnt send that number..) just
sent a less then the windows service got crazy!! will stuck at the line
" stream.read waiting for remaining packets.
is there a way that i can cancel the read after some timeout and let
the service continue the flow ??
thanks in advance.

Nov 29 '05 #1
1 1551
mu***********@gmail.com wrote:
hi guys..
im writing an application that uses windows service to listen (as a
tcplistener) for any data sent (by a tcpclient) ...
one kind of the requests might be a file sent by client and the
service should recieve it as number of packets.
the problem is: in the windows service when it detects that the data
coming is a file it make a loop (which equals the number of packets
the client will send the file by it, which will be determined by the
first packet.)
BUT.. if the client (for some reason didnt send that number..) just
sent a less then the windows service got crazy!! will stuck at the
line " stream.read waiting for remaining packets.
is there a way that i can cancel the read after some timeout and let
the service continue the flow ??


Always write these kind of services with a subsystem. You have a
listener thread which accepts connections from clients. Once a client
connects, the listener thread spawns a new instance of the subsystem
and hands the subsystem the connection. The subsystem is thus a new
thread. The listener thread then goes back to listening.

The subsystem starts starts reading data as it rolls in from the
client. After every packet read it starts a timer. If the next packet
doesn't come in before the timer ends, the subsystem aborts the
connection due to a timeout and ends itself. If the next packet does
arrive before the timer, it simply disables the timer and reads the
packet.

It's generally not a good idea to send the # of packets up front,
except if you're not using it to allocate a buffer. Never use the # of
packets send to allocate a buffer, as a malicious hacker dan send a
very large number to your service and it will crash.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 30 '05 #2

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

Similar topics

11
by: Amey Samant | last post by:
hi all i was trying to read an integer from keyboard with DataInputStream can someone explain the behaviour of the following code ???? <code> DataInputStream dis=new...
6
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
14
by: Laszlo Szijarto | last post by:
Can BinaryReader be forced to read a stream, say a TCP/IP stream or memory stream or even file stream in big endian order or do I have to write something custom to reverse the byte order? So, for...
4
by: Astronomically Confused | last post by:
using System; using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; class HttpProcessor { private Socket s;
3
by: geoffblanduk_nospam | last post by:
Given a set of intervals {i1, i2, i3, ...} a list is produced; the base items (0) are placed one at a time into the stream and after the ix one a interval item (1, 2, 3, etc) of the correct type is...
3
by: frustrated | last post by:
I am trying to share a file stream between two threads, but havent got a clue as to how to do it. The first thread will be reading the file, and the second thread will(/might) be writing to the...
0
by: Inspired | last post by:
hi guys.. im writing an application that uses windows service to listen (as a tcplistener) for any data sent (by a tcpclient) ... one kind of the requests might be a file sent by client and the...
0
by: mulham.haffar | last post by:
hi guys.. im writing an application that uses windows service to listen (as a tcplistener) for any data sent (by a tcpclient) ... one kind of the requests might be a file sent by client and the...
5
by: Hardy Wang | last post by:
Hi all, I am new to WSE 3.0, and currently reading the document shipped with installation. From sample provided (see below), I created WSE service side code, but how can I consume stream returned...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.