Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm making an IRC Client in VB.Net (2003). I'm trying to incorporate a DCC (Direct Client-To-Client) Get, but I'm having problems.

 

It only downloads the first kilobyte of information. I tried unsuccesfully using a BufferedStream.

 

Here's most of my code:

 

'TO CONNECT

           DLipEndPt = New IPEndPoint(ipAddress, port)

           'connect

           txtStatus.Text &= "Connecting, please wait..." & vbCrLf

           dSock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 'make a tcp socket

           dSock.Connect(DLipEndPt)

           netStr = New NetworkStream(dSock, True)

           dSR = New StreamReader(netStr)

           dSW = New StreamWriter(netStr)

           Application.DoEvents()

           timerGetStr.Enabled = True

'THE TIMER (set to 100)

Try

           If txtStatus.Text.ToLower.IndexOf("receiving file") = -1 Then

              ' does only the first time

               dSW.WriteLine("DCC GET " & nickName & " " & filename)

               dSW.Flush()

               txtStatus.Text &= "Sent acknowledgement..." & vbCrLf

              'the acknowledgement is in accordance to the RFC guide 
              'to the IRC protocol

               netStr = New NetworkStream(dSock)

           End If

           Application.DoEvents()

           If txtStatus.Text.ToLower.IndexOf("receiving file...") = -1 And txtStatus.Text.ToLower.IndexOf("finished") = -1 _
               Then txtStatus.Text &= "Receiving file..." & vbCrLf

           If netStr.DataAvailable Then

               Dim bytes(1024) As [byte]

               Dim data As [string] = Nothing

               Dim i As Int32 = netStr.Read(bytes, 0, bytes.Length)

               If i <> 0 Then

                   ' Translate data bytes to a ASCII string.

                   'If Not serverWindow Then Console.Write("timer is working in channel window")

                   data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

                   fSW = New StreamWriter(saveFileTo, True)

                   fSW.Write([string].Format("{0}", data))

                   fSW.Close()

                   wroteToFile = True

                   Application.DoEvents()

               End If

           ElseIf netStr.DataAvailable = False And wroteToFile Then

               If txtStatus.Text.ToLower.IndexOf("finished") = -1 Then

                   txtStatus.Text &= "Finished downloading..."

                   btnOpenFile.Enabled = True

                   btnClose.Text = "Close"

                   Beep()

                   Application.DoEvents()

               End If

           End If

       Catch ex As Exception

           errorMsg(ex)

           txtStatus.Text &= "An error has occurred..." & vbCrLf

       End Try

 

Basically, the problem is that it downloads a packet of data and stops. This is odd because I used almost the exact same code for the actual IRC part and it works great. (I also tried using dSR.Readtoend) and it also just gives me a packet of data).

 

Thank you in advance.

Posted

netStr = New NetworkStream(dSock)

And

Dim i As Int32 = netStr.Read(bytes, 0, bytes.Length)

 

This is set in a timer right ?

I think that... if you make a "new" each time... the position in the stream might change...

The only thing I see is that you're always download the first 1024 bytes in the stream that each 100milliseconds you try to do the same.

Understand my point ? You'll have to make your new elsewhere.

 

(Never maked a IRC DCC Get but... I think I'm right... If I'm wrong somebody correct me please)

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Thank you, but unfortunately, it still doesn't work. (Though, I don't even know why I had a New Netstr in a timer)

 

In response to your comment, I tried doing some kind of loop/timer where the "offset integer" would increase - then I made the "size" increase (the parameters for netstr.read()).

 

Dim offInt as integer = 0

'Timer

'...

i = netStr.read(bytes, offInt, bytes.length)

offInt += 2048

 

What is also interesting is that if I also use dSR.ReadtoEnd() it gets a different part of the file - but still only a small part.

 

It makes sense, but I feel like I'm missing a small but crucial part.

 

Unfortunately, nothing worked - except if I change the bytes(1024) --> bytes(2048) I get the first 2kb of info... I tried putting a large number in but the IDE warned me of a "overflow" problem.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...