0

I'm trying to create a file sharing program. So far, the connection and the file transfer part is taken care of. But I'm currently having problems on how to receive and save the file properly.

I can successfully receive a file if and only if I will specify its name and extension on the server side. Now my question is, how can I retrieve the name and extension of the file so that I can successfully receive the file on the server? What I mean is that I don't want to specify a name every time a file is received. Is this possible? I'm thinking of sending the file name via another network stream, but I guess there is a better way to do it.

Thanks in advance!

Here's a screen shot of the error.

https://i.stack.imgur.com/XkpZ2.png

Server Side Code

            While True
                Dim c As TcpClient = server.AcceptTcpClient
                Dim s As NetworkStream = c.GetStream

                FileOpen(1, filePath, OpenMode.Binary)
                Dim buffer(1024 - 1) As Byte
                Do While True
                    Dim bytesRead As Integer = s.Read(buffer, 0, buffer.Length)
                    If bytesRead = 0 Then Exit Do
                    FilePut(1, buffer)
                Loop
                FileClose(1)
                s.Close()
                c.Close()
            End While

Client Side Code

            Dim nstm As Stream = cli.GetStream()
            Dim fstm As Stream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
            Dim buffer(1024 - 1) As Byte
            Do While True
                Dim bytesRead As Integer = fstm.Read(buffer, 0, buffer.Length)
                If bytesRead = 0 Then Exit Do
                nstm.Write(buffer, 0, bytesRead)
            Loop
Ryklon Zen
  • 173
  • 1
  • 3
  • 19

1 Answers1

0

you cannot direct save file to dekstop, you must create new folder and allocate file to new folder. I have try create sample, this image result http://diaryanakku.files.wordpress.com/2013/01/clientsocket.png

This code referance for send file, sorry tutorial in Indonesia Lenguage but code still in English, i hope can help . http://diaryanakku.wordpress.com/2013/01/21/mengirim-file-melalui-socket-vb-net/

saysansay
  • 96
  • 3
  • Yes. Thank you for your reply. I'm gonna try this and update you ASAP. – Ryklon Zen Jan 21 '13 at 06:01
  • Update: It doesn't work even if I try to create a folder in the desktop and send their the file. I'll try the code in the site you posted now. Thanks for your time anyway. – Ryklon Zen Jan 21 '13 at 12:23