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

Sending an file as in a stream

I wonder how you can send a file in a stream using the
tcp/ip protocoll?
Nov 15 '05 #1
2 1232
http://www.csharphelp.com/archives2/archive335.html
"help" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
I wonder how you can send a file in a stream using the
tcp/ip protocoll?

Nov 15 '05 #2
William Ryan <do********@nospam.comcast.net> wrote:
http://www.csharphelp.com/archives2/archive335.html
A few dodgy bits of code in there. (I know you're not responsible, but
I'm pointing them out for the sake of posterity.)
byte[] recs = new byte[32767];
int rcount = sock.Receive(recs,recs.Length,0) ;
string clientmessage = System.Text.Encoding.ASCII.GetString(recs) ;
clientmessage = clientmessage.Substring(0,rcount);
Why not just use

string clientmessage = Encoding.ASCII.GetString (recs, 0, rcount);

?

There's also the dodginess of assuming that the whole command will come
in a single packet which worries me.

Another dodgy bit:
Byte[] sender = new Byte[1024];
sender = new Byte[1024];
sender = Encoding.ASCII.GetBytes(cmd);


Why allocate two blocks of 1K and then ignore them? (There are similar
bits elsewhere, and the use of variables declared further out than they
need to be.)

I'd personally use a TcpClient, which makes things a little bit easier.
It's important to remember that it's all a stream though, so don't
expect things to come in neatly formed amounts.

Basically, the ideas are mostly okay in the page linked above, but I'd
advise anyone to look through the code *very* carefully before adopting
any of it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

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

Similar topics

2
by: Gabriel Gudenus | last post by:
Hi Group! I am just working on a client-server network application which exchanges different Message Classes. (ObjectInputStream and ObjectOutputStream) Now i also would like to send a file...
9
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
5
by: Simon Rigby | last post by:
Hi folks, Apologies if this is not directly relevant but I was struggling to find a group with the appropriate context. So as my problem is in an aspx web site I thought I'd try here first....
1
by: kierenj | last post by:
Hi, I'm trying to send a zipfile to a client using Content-Disposition: attachment. Done it before and it works fine. My code is below: context.Response.Buffer = false;...
0
by: duclm | last post by:
Hi all, II am having problem sending zip file(binary file) using webrequest function from wince5.0 device to a webpage. It works fine for any file with size less than or equal to 1.5kb. Any bigger...
4
by: david | last post by:
hello, I have a client/server application. the server capture picture from webcam and send it to every client connected to it.the network part works good and the capture from webcam too. I...
0
by: antonyliu2002 | last post by:
I have no problem writing PDF file to hard drive on the fly with iTextSharp, but have had no luck in sending PDF as a stream in my asp.net web application. I am simply copying the example at ...
10
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area>...
0
by: silverrock7 | last post by:
Hello Friends i m stuck up to a place wherein i want to print a report which is displaying on a reportviewer. I actually want to send the report to printer directly without viewing it. i am...
20
by: tomPee | last post by:
Hi, I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following: Send over a socket: 1. Number of files to be send (not as an integer,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.