Hola, estoy haciendo un servidor http con Winsock, pero el problma resulta cuando tengo que enviar archivos binarios, ¿cómo lo puedo hacer?
Aquí va el código fuente:
Código:
Public Datos As String
Private Sub cmdComenzar_Click()

On Error Resume Next
Winsock1.LocalPort = 80
Winsock1.Listen
cmdParar.Enabled = True
cmdComenzar.Enabled = False
End Sub
Private Sub cmdParar_Click()

On Error Resume Next
Winsock1.Close
cmdParar.Enabled = False
cmdComenzar.Enabled = True
End Sub

Private Sub Form_Load()

txtIp.Text = Winsock1.LocalIP
AbrirArchivo
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
 
If Winsock1.State <> sckClosed Then Winsock1.Close
 
On Error Resume Next
Winsock1.Accept requestID
DoEvents
 
On Error Resume Next
lstConexiones.AddItem requestID
DoEvents
 
On Error Resume Next
Winsock1.SendData Datos
DoEvents
 
On Error Resume Next
Winsock1.Close
DoEvents
On Error Resume Next
Winsock1.Listen
DoEvents



End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim s As String
Winsock1.GetData s
txtHistorial.Text = s

'------------------------------------------------------'
Dim i As Long, b As String
'Método (POST o GET)
Dim Var() As String

Var = Split(txtHistorial.Text, vbNewLine)
b = Var(Val(1) - 1)
b = Mid(b, 4, Len(b))
b = Left(b, Len(b) - 9)
b = Trim(b)
DoEvents

If (b <> "/") Then
 txtDir.Text = App.Path & "\root\" & b
 On Error GoTo hola
 AbrirArchivo
 Exit Sub
 DoEvents
hola:
 txtDir.Text = App.Path & "\root\error404.html"
 AbrirArchivo
 DoEvents
Else
 txtDir.Text = App.Path & "\root\index.html"
 AbrirArchivo
 DoEvents
End If
'------------------------------------------------------'

End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

Winsock1.Close
Winsock1.Listen
End Sub
Private Function AbrirArchivo()
 
crlf$ = Chr(13) & Chr(10)
Datos = ""
Open txtDir.Text For Input As #1
 While Not EOF(1)
 Line Input #1, file_data$
 Datos = Datos & file_data$ & crlf$
 Wend
Close #1
DoEvents
End Function