473,395 Members | 2,446 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,395 software developers and data experts.

tcp sending files/messages

joedeene
583 512MB
hey there, i want to know how to send files via tcp connection, i am using a socket to connect to the tcplistener. i used to be able to send messages, i remember it was something to do with text.encoding, thats not real big, i can find that on a tutorial again, but i would really appreciate if someone showed me how to send a file. now im not connected asyncronylously. i just use the simple .connect method for now. so idk if i wanna use the beginsend, and then beginreceive, because when i just use socket.sendfile that could work, but how would i receive it on the server's side. would i have to read the network stream, and put it together? plz help... i do have some code, im willing to show if anyone suggests im just getting people to do my "homework". ok, plz help, thanks in advance =)
Jul 24 '08 #1
5 1157
secutos
15
First, know that this will most likely (99%) not answer your question, but will instead give you a headstart. If you were transferring a big file, you would probably have to send bits at a time. First, you convert that "big file" into a byte array. You cut off a bit of the byte array to send. For that bit you just cut off, tag it so the other side knows that there is more to come (there is a lot more byte arrays to send). To tag it, add a few bytes with a special code like "UNFINISHED". When the other side reads the byte array and sees "UNFINISHED", it stores it into a bigger byte array storage and waits for more.

Correct me if i'm wrong.
Aug 15 '08 #2
Plater
7,872 Expert 4TB
1) Connect socket
2) Open file
3) Send file bytes on socket
4) Repeat step 3 until all bytes are sent
5) Close file
6) Close socket (or whatever you feel like for your protocol)
Aug 15 '08 #3
joedeene
583 512MB
1) Connect socket
2) Open file
3) Send file bytes on socket
4) Repeat step 3 until all bytes are sent
5) Close file
6) Close socket (or whatever you feel like for your protocol)

how would i come across doing this ? like for step 3 use the socket.sendfile? and how to read it? like i'd rather do a network stream from just the tcpclient.getstream and write to that.
Aug 15 '08 #4
Plater
7,872 Expert 4TB
How you do it is up to you.
You just send bytes accross a socket. So open your file up, read in the bytes and send the bytes over the socket.
How you control the talking back and forth is all up to you.
Aug 15 '08 #5
joedeene
583 512MB
How you do it is up to you.
You just send bytes accross a socket. So open your file up, read in the bytes and send the bytes over the socket.
How you control the talking back and forth is all up to you.

i know that but i tried sending a simple small jpeg over the networkstream and i'd get most of it, but it would should like a gray(blank) spot where i guess it didnt receive all of the data, idk i guess i'll work on it, and i dont remember that code either, i'll just google some more
Aug 15 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
2
by: Nis Sarup | last post by:
A customer of mine wants to make a newsletter for their website. The newsletter should be HTML with images and sent to a database of her subscribers. They would like a script where they can easily...
0
by: Dragos Marian Barbu | last post by:
Recently I tried to develop a function to help me sending e-mail messages with more than one attachment. Everything is working OK when I am sebding messages with one attachment, but when I try to...
0
by: Buddy Ackerman | last post by:
I'm sending file to the client (see sample code below) but when I send a large file the user gets a document contains no data message. response.contenttype = "application/x-unknown" myheader =...
0
by: Buddy Ackerman | last post by:
I'm sending file to the client (see sample code below) but when I send a large file the user gets a document contains no data message. response.contenttype = "application/x-unknown" myheader =...
3
by: Jeff | last post by:
Hey ASP.NET 2.0 This the ObjectDataSource in my UserControl, <asp:ObjectDataSource ID="odsMessage" runat="server" SelectMethod="ExecuteMessage" TypeName="AH.MyNetwork.BLL.Network.Message">...
8
by: Robert Dufour | last post by:
Dim message As New MailMessage("mymail@mydomain.com", "mymail@mydomain.com", "Test", "Test") Dim emailClient As New SmtpClient("localhost") emailClient.Send(message) The IIS server is...
2
by: nautonnier | last post by:
Hello, I have a C# app that spawns several processes each containing a console app written by another developer in C++. The console app was written first to be just like a console app: it...
1
by: robbiesmith79 | last post by:
Just so this is out there on the web, I battled the past 24 hours about this. Background info... I developed a ecommerce website in PHP 4 on a shared linux hosting plan from GoDaddy and had the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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,...

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.