Search code examples
pythonvb6winsockbasic

Send python string using vb6 winsock


I assume I don't know python. This script sends a simple string over lan to a lan address (from my pc to a python server)

-------------------------------------------------------
    import socket
#
host ="192.168.0.17"
port =49280
#
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
#
s.sendall("set MIXER:Current/InCh/Fader/On 1 0 1\n".encode())
s.recv(1500)
s.close
-----------------------------------------------

I would like to send the same string but using vb6....

--------------------------------------------
    Private Sub Command3_Click()
Winsock1.RemoteHost = "192.168.0.17"
Winsock1.RemotePort = 49280
Winsock1.Protocol = sckTCPProtocol
Winsock1.Connect
winsock1

  Dim stringa1, stringa As String
  Dim Data() As Byte
  stringa = "set MIXER:Current/InCh/Fader/On 1 0 1\n"
  Data = StrConv(stringa, vbFromUnicode)
  
    Winsock1.SendData Data

End Sub
----------------------------------------------

but unfortunately it doesn't work. With the first script, my remote python server responds correctly, with the script in vb6 the server shows no signs of life Anyone can tell me what mistake I make? thanks to all and good continuation Mario


Solution

  • Based upon this table:

    https://www.quackit.com/python/reference/python_3_escape_sequences.cfm

    a \n in Python is a line feed. So in VB6 that would be vbLf.

    So try changing your line to this:

    stringa = "set MIXER:Current/InCh/Fader/On 1 0 1" & vbLf