473,654 Members | 3,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending file

Hi, I have a problem with sending a file.
I have a client application that connects to a server and sends the
string "data". Then it sends a file. If the server receives "data",
the method getCsv() is started (this receives the file)

The file however isn't received completely (most of the time)

this is my servercode:

Imports System.Net.Sock ets
Imports System.Text
Imports System.Xml
Imports System.IO
Class server

Shared Sub readStream(ByVa l tcpCl As TcpClient, ByVal netwstr
As NetworkStream)
Dim clientdata As String
Dim bytes(tcpCl.Rec eiveBufferSize) As Byte
Do
clientdata = ""
If (netwstr.DataAv ailable) Then
netwstr.Read(by tes, 0,
CInt(tcpCl.Rece iveBufferSize))
clientdata = Encoding.ASCII. GetString(bytes )
End If
If (clientdata.Com pareTo("data") =
0) Then
Exit Sub
End If
Loop Until False
End Sub
Shared Sub getCsv(ByVal tcpCl As TcpClient, ByVal netwstr As
NetworkStream)
Dim bytes2(tcpCl.Re ceiveBufferSize ) As Byte

Dim myCompleteMessa ge As String
Dim numberOfBytesRe ad As Integer
Do
numberOfBytesRe ad = netwstr.Read(by tes2, 0,
bytes2.Length)
myCompleteMessa ge =
[String].Concat(myCompl eteMessage,
Encoding.ASCII. GetString(bytes 2, 0, numberOfBytesRe ad))
Loop While netwstr.DataAva ilable
Dim fi As New FileInfo("Test. csv")
Dim sw As StreamWriter = fi.CreateText()
sw.Write(myComp leteMessage)
sw.Close()
Console.WriteLi ne("Data received")
End Sub

Shared Sub Main()
Const portNumber As Integer = 1234
Dim tcpListener As New TcpListener(por tNumber)
Dim tcpClient As TcpClient

tcpListener.Sta rt()
Console.WriteLi ne("Listening.. .")

Try
tcpClient = tcpListener.Acc eptTcpClient()
Console.WriteLi ne("Connection
accepted.")
Dim networkStream As NetworkStream =
tcpClient.GetSt ream()
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte

Do
readStream(tcpC lient, networkStream)
getCsv(tcpClien t, networkStream)
Loop Until False

Catch e As Exception
Console.WriteLi ne(e.ToString() )
Console.ReadLin e()

End Try

End Sub
End Class


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #1
1 1827
If the server is reading information faster than it's arriving from the
client then the "DataAvaila ble" property is probably returning false at some
point and ending the loop. When I've sent files over a TCP/IP connection I
usually had to send the size of the file before actually sending the file so
that the server knows when all of the data has been received. Sort of a
header with the number of bytes being sent. To really be thorough you may
have to create a 2-way protocol and use a timer. This way the server can
continue reading until all of the data is received and requery the client if
a specified amount of time elapses (a user-defined time-out) before all of
the data is received.
"Henk" <kl*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:40******** @127.0.0.1...
Hi, I have a problem with sending a file.
I have a client application that connects to a server and sends the
string "data". Then it sends a file. If the server receives "data",
the method getCsv() is started (this receives the file)

The file however isn't received completely (most of the time)

this is my servercode:

Imports System.Net.Sock ets
Imports System.Text
Imports System.Xml
Imports System.IO
Class server

Shared Sub readStream(ByVa l tcpCl As TcpClient, ByVal netwstr
As NetworkStream)
Dim clientdata As String
Dim bytes(tcpCl.Rec eiveBufferSize) As Byte
Do
clientdata = ""
If (netwstr.DataAv ailable) Then
netwstr.Read(by tes, 0,
CInt(tcpCl.Rece iveBufferSize))
clientdata = Encoding.ASCII. GetString(bytes )
End If
If (clientdata.Com pareTo("data") =
0) Then
Exit Sub
End If
Loop Until False
End Sub
Shared Sub getCsv(ByVal tcpCl As TcpClient, ByVal netwstr As
NetworkStream)
Dim bytes2(tcpCl.Re ceiveBufferSize ) As Byte

Dim myCompleteMessa ge As String
Dim numberOfBytesRe ad As Integer
Do
numberOfBytesRe ad = netwstr.Read(by tes2, 0,
bytes2.Length)
myCompleteMessa ge =
[String].Concat(myCompl eteMessage,
Encoding.ASCII. GetString(bytes 2, 0, numberOfBytesRe ad))
Loop While netwstr.DataAva ilable
Dim fi As New FileInfo("Test. csv")
Dim sw As StreamWriter = fi.CreateText()
sw.Write(myComp leteMessage)
sw.Close()
Console.WriteLi ne("Data received")
End Sub

Shared Sub Main()
Const portNumber As Integer = 1234
Dim tcpListener As New TcpListener(por tNumber)
Dim tcpClient As TcpClient

tcpListener.Sta rt()
Console.WriteLi ne("Listening.. .")

Try
tcpClient = tcpListener.Acc eptTcpClient()
Console.WriteLi ne("Connection
accepted.")
Dim networkStream As NetworkStream =
tcpClient.GetSt ream()
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte

Do
readStream(tcpC lient, networkStream)
getCsv(tcpClien t, networkStream)
Loop Until False

Catch e As Exception
Console.WriteLi ne(e.ToString() )
Console.ReadLin e()

End Try

End Sub
End Class


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #2

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

Similar topics

3
7041
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt. Obviuosly, the file is fine on the server, so the attachment code I am using must be corrupting it, but I dont know what it is: // send email with attachment function emailAttachment($to, $subject, $message, $name, $email,
3
5857
by: Serge Myrand | last post by:
Hi everybody, The following code for sending email (found on msn I think) works find when used in a .VBS file. I double click the file and the mail is send. When I use the same code in my .ASP application I get the following message: "The pickup directory path is required and was not specified" Where to specify that directory?
2
2760
by: Ebrahim | last post by:
Does any one have any suggestion of Sending Files over a Network ? using TcpClient class in C#. I need suggestions on transferring huge files ( > 5MB) reliably over the stream . Also any kind of files could have to be transferred .ie Exe , mp3 , dat .. any kind . Do i need to convert these files ? When i normally send text files i convert them to Ascii bytes using Encoding.Ascii.getBytes() . Will it work with Exe files and all others ??...
9
3276
by: savvy | last post by:
i'm trying to compile a simple console application for sending a mail, my main idea is to schedule it to a particular time for sending mails using the windows schedular task lateron. Therefore i need an exe file to make that work. I compiled my file Emailtest.cs using this command line csc /r:System.Web.dll Emailtest.cs and i got an .exe file but when clicking it or executing it i'm not receiving any mail. I dont know where the problem is...
0
1472
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 = "attachment;filename=order123.zip" Response.AddHeader("Content-Disposition", myheader) Response.WriteFile(FileName, StartPos, FileSize)
0
1154
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 = "attachment;filename=order123.zip" Response.AddHeader("Content-Disposition", myheader) Response.WriteFile(FileName, StartPos, FileSize)
9
4915
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 strReturnData As String = _ System.Text.Encoding.ASCII.GetString(receiveBytes)
0
1855
by: remya1000 | last post by:
by using FTP i can send files to server using vb.net. if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by one,then whethere we can show the progress of each file sending to server in progress bar. so that the FTP clients can see the progress of file sending to the server. any idea how we can do this to show the progress of each file sending. if we...
0
1642
by: toto1980 | last post by:
Hi; I tried look for a simple way of sending a file using sockets, I found one in the old forums but I am not sure why the file when it is sent, the client side some how receive wrong contents, and when having a big file let us say 200 KB, the file transfer is not complete. Here is the code: Client side (receiver): /////////////////////////Receiving a file/////////////////////// Code: FILE *fp; char name="t.txt";
7
3331
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of guests added. form.php function createGuestNameAndEmailElements() {
0
8285
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
8706
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
8475
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
8591
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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
5621
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
4149
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2709
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
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.