I seem to be having a problem either sending byte data or receiving byte data or both using Winsock. When I get the data in DataArrival into a byte array it isn't correct; it's garbage.
Here is my code - Client sends byte data to Server
Client Code:
Server Code:
When I look at the data in "BYTE_ARRAY.BYT" using a Hex Editor I can see that the data is garbage and is not even close to what it should look like which would be the "mypicture.jpg" file format.
Here is my code - Client sends byte data to Server
Client Code:
Code:
Dim b() As Byte
Dim DataSent As Boolean
Private Sub Form_Load()
Open App.Path & "\mypicture.jpg" For Binary Access Read As #1
ReDim b(0 To LOF(1) - 1)
Get #1, , b
Close #1
End Sub
Private Sub Command1_Click()
Winsock1.Close
Winsock1.Connect "xxx.xxx.xxx.xxx", 8888
End Sub
Private Sub Winsock1_Connect()
DataSent = False
Winsock1.SendData b
Do While DataSent = False
DoEvents
Loop
Winsock1.Close
End Sub
Private Sub Winsock1_SendComplete()
DataSent = True
End Sub
Server Code:
Code:
Option Explicit
Dim Buffer() As Byte
Private Sub Command1_Click()
Winsock1.Close
Winsock1.LocalPort = 8888
Winsock1.Listen
End Sub
Private Sub Winsock1_Close()
Open App.Path & "\BYTE_ARRAY.BYT" For Binary As #1
Put #1, 1, Buffer
Close #1
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
Buffer = ""
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData Buffer
End Sub