Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey every body

i'm using winsock to do manipulation between server and client ,Im searching for a month to know how to send file.
but i dont found any think , i try to do this code:
in the server:
Private Function ReadFile(ByVal filePath As String)
      Dim fs As IO.FileStream
      Dim br As IO.BinaryReader
      Dim bytes(10) As Byte
      Dim TheFile As String = ""
      Dim cutpath() As String = filePath.Split("\")
      fs = New IO.FileStream(filePath, IO.FileMode.Open, IO.FileAccess.Read)
      br = New IO.BinaryReader(fs)

      Dim byteRead As Byte
      Dim x As Integer
      For x = 0 To br.BaseStream.Length() - 1
        byteRead = br.ReadByte
        TheFile += CStr(byteRead)
      Next
      br.Close()
      Return "!Binary!" & TheFile & "*" & cutpath(cutpath.Length - 1)
      MsgBox("!Binary!" & TheFile & "*" & cutpath(cutpath.Length - 1))
    End Function

in the client:
Private Sub SaveFile(ByVal TheBinaries As String)
      'TheBinaires have Data*NameOfFile, this will seperate the two.
      Dim TheBin() As String = TheBinaries.Split("*")
      Dim fs As IO.FileStream
      Dim bw As IO.BinaryWriter
      fs = New IO.FileStream("d:\dounia\" & "copy_" & TheBin(1), IO.FileMode.CreateNew, IO.FileAccess.Write)
      bw = New IO.BinaryWriter(fs)
      bw.Write(TheBin(0))

      'bw.Write(byteRead)
      bw.Flush()
      fs.Close()
      bw.Close()
    End Sub


that not work very well because whene im open the file in the client i found all the data in binery so i cant read the file, if somme one know where is the problem plsss help, if some know anothet solution pls helllllpppp thnx
Posted
Comments
Sergey Alexandrovich Kryukov 12-Jan-12 3:15am    
Where are the sockets in your code?
Any specific reason you don't want to use System.Net.Sockets? TcpListener/TcpClient?
--SA
dodita 14-Jan-12 17:52pm    
im using winsock i don't need socket in my code.i use this function like that in

server :

<pre>Winsock1.SendData("file" & ReadFile(TextBox3.Text))</pre>

in cliet :

Winsock1.GetData(data)
SaveFile(data)

the probleme is not in socket or in winsock the file is send succsesfully but i give u example if i put text in file.txt and i send it.in client i found the file but i can't read the text because it's in binery so i need a function to convert this file from binery to normal language if u know how plss some helpp i wish u unterstand my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900