Winsock operates asynchronously, that means that control is passed back to your code immediately the SendData has been executed - not when it has actually sent the data - so you're closing the connection before it's had a chance to send the data.
You should use the Winsock_SendComplete event, which is triggered when the data has actually been sent, to close the socket.
Public Sub cmdDisconnect()
If WinsockSendFinish = True Then
Winsock.Close
End If
If Winsock.State = sckClosed Then
WinsockSendFinish = False
End If
While Not WinsockSendFinish
DoEvents
Wend
End Sub
Public Sub cmdSend(tekst As String)
broj = 0
Winsock.SendData Chr(13) & Chr(10)
Winsock.SendData tekst & Chr(13) & Chr(10)
WinsockSendFinish = True
End Sub
Private boSent As Boolean
Private Sub Winsock_SendComplete()
boSent = True
End Sub
Public Sub cmdSend(tekst As String)
broj = 0
Winsock.SendData Chr(13) & Chr(10)
boSent = False
Winsock.SendData tekst & Chr(13) & Chr(10)
Do Until boSent = True
DoEvents
Loop
Winsock.Close
End Sub