Ok well i got most of it sorted out but i got a new problem an i can't seem to fix it if anyone has time can you optimize my code? the problem i'm having is when i send a file from computer A to computer B , Computer B trys to saves as computer A's directory EG computer A say C:\documents\usernamex\desktop while computer B c:\documents\diffusernamek\desktop so when i send a file to b from a it trys saving as a's directory but it doesnt exist becuase its on a an vice versa?
Code:Private Sub senddataa(sFile As String, sSaveAs As String, tcpCtl As Winsock) On Error GoTo ErrHandler Dim sSend As String, sBuf As String Dim ifreefile As Integer Dim lRead As Long, lLen As Long, lThisRead As Long, lLastRead As Long ifreefile = FreeFile ' Open file for binary access: Open sFile For Binary As #ifreefile lLen = LOF(ifreefile) ' Loop through the file, loading it up in chunks of 64k: Do While lRead < lLen lThisRead = 65536 If lThisRead + lRead > lLen Then lThisRead = lLen - lRead End If If Not lThisRead = lLastRead Then sBuf = Space$(lThisRead) End If Get #ifreefile, , sBuf lRead = lRead + lThisRead sSend = sSend & sBuf Loop lTotal = lLen Close ifreefile bSendingFile = True '// Send the file notification tcpCtl.senddata "FILE" & sSaveAs DoEvents '// Send the file tcpCtl.senddata sSend DoEvents '// Finished tcpCtl.senddata "FILEEND" bSendingFile = False Exit Sub ErrHandler: MsgBox "Err " & Err & " : " & Error End SubCode:Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long) Dim strData As String Dim ifreefile Winsock2.getdata strData If Right$(strData, 7) = "FILEEND" Then bFileArriving = False sArriving = sArriving & Left$(strData, Len(strData) - 7) ifreefile = FreeFile Open sFile For Binary As #ifreefile Put #ifreefile, 1, sArriving Close #ifreefile lblProgress = "File Transfer Complete" ElseIf Left$(strData, 4) = "FILE" Then bFileArriving = True sFile = Right$(strData, Len(strData) - 4) ElseIf bFileArriving Then lblProgress = "Receiving " & bytesTotal & " Bytes For " & sFile & " From " & Winsock1.RemoteHostIP Label5.Caption = "Connected" sArriving = sArriving & strData End If End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim strData As String Dim ifreefile Winsock1.getdata strData If Right$(strData, 7) = "FILEEND" Then bFileArriving = False sArriving = sArriving & Left$(strData, Len(strData) - 7) ifreefile = FreeFile Open sFile For Binary As #ifreefile Put #ifreefile, 1, sArriving Close #ifreefile lblProgress = "File Transfer Complete" ElseIf Left$(strData, 4) = "FILE" Then bFileArriving = True sFile = Right$(strData, Len(strData) - 4) ElseIf bFileArriving Then lblProgress = "Receiving " & bytesTotal & " Bytes For " & sFile & " From " & Winsock1.RemoteHostIP sArriving = sArriving & strData End If End SubCode:Private Sub Command4_Click() If Dir$(txtFile) = "" Then MsgBox "File Does Not Exist" Else senddataa txtFile, GetFileName(txtFile), Winsock1 End If End Sub Private Sub Command5_Click() If Dir$(txtFile) = "" Then MsgBox "File Does Not Exist" Else senddataa txtFile, GetFileName(txtFile), Winsock2 End If End SubI make command 4 visible when its the listener or host an command5 hidden vice versa if they connected other way can anyone helpCode:Public Function GetFileName(flname As String) As String Dim posn As Integer, i As Integer Dim fName As String posn = 0 For i = 1 To Len(flname) If (Mid(flname, i, 1) = "\") Then posn = i Next i fName = Right(flname, Len(flname) - posn) GetFileName = fName End Function![]()




Reply With Quote