IRC DCC Get

adude

Member
Joined
Aug 19, 2003
Messages
22
Hi,

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

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

Heres most of my code:

[VB]

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

[/VB]

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.
 
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 youre always download the first 1024 bytes in the stream that each 100milliseconds you try to do the same.
Understand my point ? Youll have to make your new elsewhere.

(Never maked a IRC DCC Get but... I think Im right... If Im wrong somebody correct me please)
 
Thank you, but unfortunately, it still doesnt work. (Though, I dont 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()).

Code:
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 Im 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.
 


Write your reply...
Back
Top