sending file

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Henk (klesjezot_at_hotmail-dot-com.no-spam.invalid)
Date: 04/01/04


Date: 1 Apr 2004 06:31:10 -0600

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.Sockets
Imports System.Text
Imports System.Xml
Imports System.IO

Class server

    Shared Sub readStream(ByVal tcpCl As TcpClient, ByVal netwstr
As NetworkStream)
        Dim clientdata As String
        Dim bytes(tcpCl.ReceiveBufferSize) As Byte
        Do
            clientdata = ""
            If (netwstr.DataAvailable) Then
                netwstr.Read(bytes, 0,
CInt(tcpCl.ReceiveBufferSize))
                clientdata = Encoding.ASCII.GetString(bytes)
            End If
            If (clientdata.CompareTo("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.ReceiveBufferSize) As Byte

        Dim myCompleteMessage As String
        Dim numberOfBytesRead As Integer
        Do
            numberOfBytesRead = netwstr.Read(bytes2, 0,
bytes2.Length)
            myCompleteMessage =
[String].Concat(myCompleteMessage,
Encoding.ASCII.GetString(bytes2, 0, numberOfBytesRead))
        Loop While netwstr.DataAvailable
        Dim fi As New FileInfo("Test.csv")
        Dim sw As StreamWriter = fi.CreateText()
        sw.Write(myCompleteMessage)
        sw.Close()
        Console.WriteLine("Data received")
    End Sub

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

        tcpListener.Start()
        Console.WriteLine("Listening...")

        Try
            tcpClient = tcpListener.AcceptTcpClient()
            Console.WriteLine("Connection
accepted.")
            Dim networkStream As NetworkStream =
tcpClient.GetStream()
            Dim bytes(tcpClient.ReceiveBufferSize) As Byte

            Do
                readStream(tcpClient, networkStream)
                getCsv(tcpClient, networkStream)
            Loop Until False

        Catch e As Exception
            Console.WriteLine(e.ToString())
            Console.ReadLine()

        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 =---



Relevant Pages

  • Re: Automating dialog with web server from VB.NET
    ... of the problem was learning how to handle the firewall proxy server. ... > Since I have no Lotus Notes web application at hand, I test on an aspx page. ... > Imports System.Collections.Specialized ... > Sub Main ...
    (microsoft.public.dotnet.languages.vb)
  • Re: client close the socket. how the server knows?
    ... the server know that the socket is closed from the client side. ... > Private Delegate Sub UpdateListBoxDel(ByVal Data As String) ... > Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • .Net remoting doesnt work in Wan area.
    ... i try to broadcast events raised in server to ... Public Sub DoSomething ... Dim del As ... Dim clientProv As New BinaryClientFormatterSinkProvider ...
    (microsoft.public.dotnet.framework)
  • Re: How to get fastForward to work in the Windows Media Player Control?
    ... Sub ShutMeDown ... WMP is *client side*. ... Even if you could try to run WMP somehow at the server end, ... "Player" is not a child of Form1, it's a child of the Document object. ...
    (microsoft.public.windowsmedia.player.web)
  • Re: Chat client/server print failed
    ... is the print statement in the send_msg_all sub. ... leave the server running for testing purposes. ... # This would be the end of file, so close the client ... # just read means there is a complete request waiting ...
    (comp.lang.perl.misc)