473,545 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about NetworkStream

In a simple code I do something like this in a synchronous connection:
-*server*-----------------------------
ClientTcp=Liste nerTcp.AcceptTc pClient();
NetworkStream nstream=ClientT cp.GetStream();
ImagePictureBox .Image.Save(nst ream,System.Dra wing.Imaging.Im ageFormat.Jpeg) ;
nstream.Close() ;

If I don't close the underlying socket with nstream.Close() de image
never gets to the client. Why does this occur since nstream is
unbuffered it should get to the client. In the client I do something
like this:
-*client*----------------------------
NetworkStream nstream=ClientT cp.GetStream();
//Get image data as JPEG
ImagePictureBox .Image=Image.Fr omStream(nstrea m);
nstream.Close() ;

The image never gets to client if I don't close the socket in the
server but this forces me to establish connections after connections
and it gets slow. Should I move to asynchronous socket connections...
does this problem persists in asynchronous mode? If I want to get an
image passed to the client I have to make the client acknowledge the
server at the end of image... and also have to read the bytes
asynchronously using this format: |Size|Byte Data|.

Any lights on this would be great,
Nuno Magalhães.

Nov 17 '05 #1
2 2586
What are you doing on the server side. If you block until you get 0, then
only socket shutdown will produce that on your Receive. Prepend the len
(int or short) before the byte stream. Then read the len bytes and loop
until you read that many bytes. So break your stream up into messages (which
are length prepended stream of bytes.)

--
William Stacey [MVP]

"Nuno Magalhaes" <nu************ @hotmail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
In a simple code I do something like this in a synchronous connection:
-*server*-----------------------------
ClientTcp=Liste nerTcp.AcceptTc pClient();
NetworkStream nstream=ClientT cp.GetStream();
ImagePictureBox .Image.Save(nst ream,System.Dra wing.Imaging.Im ageFormat.Jpeg) ;
nstream.Close() ;

If I don't close the underlying socket with nstream.Close() de image
never gets to the client. Why does this occur since nstream is
unbuffered it should get to the client. In the client I do something
like this:
-*client*----------------------------
NetworkStream nstream=ClientT cp.GetStream();
//Get image data as JPEG
ImagePictureBox .Image=Image.Fr omStream(nstrea m);
nstream.Close() ;

The image never gets to client if I don't close the socket in the
server but this forces me to establish connections after connections
and it gets slow. Should I move to asynchronous socket connections...
does this problem persists in asynchronous mode? If I want to get an
image passed to the client I have to make the client acknowledge the
server at the end of image... and also have to read the bytes
asynchronously using this format: |Size|Byte Data|.

Any lights on this would be great,
Nuno Magalhães.
Nov 17 '05 #2
Thank you your response. I guess you're right... I'll have to use the
read and write methods of the NetworkStream.

Thank you,
Nuno Magalhães.

William Stacey [MVP] wrote:
What are you doing on the server side. If you block until you get 0, then
only socket shutdown will produce that on your Receive. Prepend the len
(int or short) before the byte stream. Then read the len bytes and loop
until you read that many bytes. So break your stream up into messages (which
are length prepended stream of bytes.)

--
William Stacey [MVP]

"Nuno Magalhaes" <nu************ @hotmail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
In a simple code I do something like this in a synchronous connection:
-*server*-----------------------------
ClientTcp=Liste nerTcp.AcceptTc pClient();
NetworkStream nstream=ClientT cp.GetStream();
ImagePictureBox .Image.Save(nst ream,System.Dra wing.Imaging.Im ageFormat.Jpeg) ;
nstream.Close() ;

If I don't close the underlying socket with nstream.Close() de image
never gets to the client. Why does this occur since nstream is
unbuffered it should get to the client. In the client I do something
like this:
-*client*----------------------------
NetworkStream nstream=ClientT cp.GetStream();
//Get image data as JPEG
ImagePictureBox .Image=Image.Fr omStream(nstrea m);
nstream.Close() ;

The image never gets to client if I don't close the socket in the
server but this forces me to establish connections after connections
and it gets slow. Should I move to asynchronous socket connections...
does this problem persists in asynchronous mode? If I want to get an
image passed to the client I have to make the client acknowledge the
server at the end of image... and also have to read the bytes
asynchronously using this format: |Size|Byte Data|.

Any lights on this would be great,
Nuno Magalhães.


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...
0
953
by: Swami | last post by:
I wrote a server (code pasted below) that is supposed to receive ASCII text files. For each file I receive, I change some header info and save it as another file on my end. For some reason, the files that I receive come as garbage characters. However, when I send the same file as a string, it goes through properly. Is there some extra...
4
7180
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create one of these things and it WON'T read data. If I set a breakpoint in my EndRead callback, it never goes off. NOTHING is different from anywhere...
4
7070
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer;...
0
1525
by: Abubakar | last post by:
Hi, try { int x = ns.Read(readbuffer, 0, readbuffer.Length); } catch (System.IO.IOException ioexception) { UINotifications.ServerMessageDisplay(ioexception.ToString( )); }
12
2018
by: Brian Henry | last post by:
I wrote a simple client / server app (nothing major, just sends text) it works fine locally on the same system, but once i move the client to a remote system it errors and gives me "No connection could be made because the target machine actively refused it" what exactly does that mean? the targed machine actively refused it? i have port...
1
4356
by: Rob T | last post by:
Hi, I have a simple little program that I'm going to use to access our SMTP server. The below code works perfectly fine, but my question is if I were to try to execute the last line (info=streamReader.ReadLine) another time, the program hangs. Most likely since the SMTP server has no other responses to post. Is there a way to make the...
7
4247
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...
6
7254
by: Ryan Liu | last post by:
Hi, I have some basic question about NetworkStream, can someone explain to me? Thanks a lot in advance! TcpClient has a GetStream() method return a NetworkStream for read and write. I remember there are 2 streams in Java, one for read, one for write. If I just use synchronous Read() and Write() method:
0
7468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
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...
0
7656
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. ...
1
7423
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...
0
5972
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...
1
5329
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...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1884
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
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.