MSWinsock.Winsock event handling in VisualBasic - events

I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using the following code:
Dim Winsock1 As Winsock 'Object type definition
Sub Init()
Set Winsock1 = CreateObject("MSWinsock.Winsock") 'Object initialization
Winsock1.RemoteHost = "MyHost"
Winsock1.RemotePort = "22"
Winsock1.Connect
Do While (Winsock1.State <> sckConnected)
Sleep 200
Loop
End Sub
'Callback handler
Private Sub Winsock1_Connect()
MsgBox "Winsock1::Connect"
End Sub
But it never goes to Winsock1_Connect subroutine although Winsock1.State is "Connected".
I want to use standard MS library because I don't have administrative rights on my PC and I'm not able to register some custom libraries.
Can anybody tell me, where I'm wrong?

Are you stuck using MSWinsock?
Here is a site/tutorial using a custom winsock object.
Also... You need to declare Winsock1 WithEvents within a "Class" module:
Private WithEvents Winsock1 As Winsock
And finally, make sure you reference the winsock ocx control.
Tools -> References -> Browse -> %SYSEM%\MSWINSCK.OCX

Documentation about Winsock Control:
http://msdn.microsoft.com/en-us/library/aa228119%28v=vs.60%29.aspx
Example here:
http://support.microsoft.com/kb/163999/en-us
My short example with event handling in VBscript:
Dim sock
Set sock = WScript.CreateObject("MSWinsock.Winsock","sock_")
sock.RemoteHost = "www.yandex.com"
sock.RemotePort = "80"
sock.Connect
Dim received
received = 0
Sub sock_Connect()
WScript.Echo "[sock] Connection Successful!"
sock.SendData "GET / HTTP/1.1"& vbCrLf & "Host: " & sock.RemoteHost & vbCrLf & vbCrLf
End Sub
Sub sock_Close()
WScript.Echo "[sock] Connection closed!"
End Sub
Sub sock_DataArrival(Byval b)
Dim data
sock.GetData data, vbString
received = received + b
WScript.Echo "---------------------------------------"
WScript.Echo " Bytes received: " & b & " ( Total: " & received & " )"
WScript.Echo "---------------------------------------"
WScript.Echo data
End Sub
'Wait for server close connection
Do While sock.State <> 8
rem WScript.Echo sock.State
WScript.Sleep 1000
Loop
Output will be:
cscript /nologo sockhttp.vbs
[sock] Connection Successful!
-------------------------------
Bytes received: 1376 ( Total: 1376 )
-------------------------------
HTTP/1.1 200 Ok
Date: Mon, 08 Dec 2014 15:41:36 GMT
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache,no-store,max-age=0,must-revalidate
Expires: Mon, 08 Dec 2014 15:41:36 GMT
...

Related

How to check if a video or an audio stream is online or not in Vbscript?

I wonder what is the parameter or the value to look for to check if a video or audio stream is online or not in vbscript ?
So this what i have tried as code until now, but, it give me a wrong results, because i have checked all those streams with VLC and they works 5/5, but with this script the second and the third stream give me as offline ??
Option Explicit
Dim Title,URLArray,URL,ws,Msg,Data
Title = "Audio and Video Stream Checker"
URLArray = Array("https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8"_
,"http://aska.ru-hoster.com:8053/autodj"_
,"http://www.chocradios.ch/djbuzzradio_windows.mp3.asx")
Call ForceCScriptExecution()
For Each URL in URLArray
wscript.echo "The stream " & URL & " is "& CheckOnline(URL) & vbCrlf & String(100,"-")
Next
'----------------------------------------------------
Function CheckOnline(URL)
On Error Resume Next
Const WHR_EnableRedirects = 6
Dim h,AllResponseHeaders
Set h = CreateObject("WinHttp.WinHttpRequest.5.1")
h.Option(WHR_EnableRedirects) = False 'disable redirects
h.Open "HEAD", URL , False
h.Send()
AllResponseHeaders = h.GetAllResponseHeaders()
wscript.echo AllResponseHeaders
If Err.number = 0 Then
If h.status = 200 OR h.status = 201 OR h.status = 202 OR h.status = 203 OR h.status = 204 Then
CheckOnline = "ONLINE"
Else
CheckOnline = "OFFLINE"
End IF
Else
CheckOnline = "OFFLINE" & vbCrlf & Err.Description
On Error Goto 0
End IF
End Function
'----------------------------------------------------
Sub ForceCScriptExecution()
Dim Arg, Str, cmd
cmd = "CMD /K Title " & Title &" & color 0A & "
If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
For Each Arg In WScript.Arguments
If InStr( Arg, " " ) Then Arg = """" & Arg & """"
Str = Str & " " & Arg
Next
CreateObject( "WScript.Shell" ).Run _
cmd & "cscript //nologo """ & _
WScript.ScriptFullName & _
""" " & Str
WScript.Quit
End If
End Sub
'--------------------------------------------------
I got as response like this :
Cache-Control: no-cache
Date: Sat, 28 Dec 2019 00:14:27 GMT
Content-Length: 232
Content-Type: application/vnd.apple.mpegurl
Accept-Ranges: bytes
Server: WowzaStreamingEngine/4.7.8
Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
The stream https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8 is ONLINE
-------------------------------------------------------------------------------
Cache-Control: no-cache
Date: Sat, 28 Dec 2019 00:14:28 GMT
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Server: Icecast 2.4.2
The stream http://aska.ru-hoster.com:8053/autodj is OFFLINE
-------------------------------------------------------------------------------
Connection: keep-alive
Date: Sat, 28 Dec 2019 00:14:28 GMT
Content-Type: text/html; charset=iso-8859-1
Location: https://www.chocradios.ch/djbuzzradio_windows.mp3.asx
Server: nginx
X-Powered-By: PleskLin
The stream http://www.chocradios.ch/djbuzzradio_windows.mp3.asx is OFFLINE
-------------------------------------------------------------------------------
Here is possible implementation with WMP:
Option Explicit
forceCScriptExecution "Audio and Video Stream Checker"
testStreams
Sub testStreams()
Dim urls
Dim sourceUrl
Dim isOnline
Dim mediaName
Dim streamUrl
urls = Array(_
"https://5ac31d8a4c9af.streamlock.net/saheltv/_definst_/myStream/chunklist_w956788169.m3u8", _
"http://aska.ru-hoster.com:8053/autodj", _
"http://www.chocradios.ch/djbuzzradio_windows.mp3.asx" _
)
For Each sourceUrl In urls
WScript.Echo ""
WScript.Echo "sourceUrl " & sourceUrl
WScript.Echo "Checking..."
checkStreamOnline sourceUrl, 30, isOnline, mediaName, streamUrl
WScript.Echo "isOnline " & isOnline
WScript.Echo "mediaName " & mediaName
WScript.Echo "streamUrl " & streamUrl
Next
End Sub
Sub checkStreamOnline(sourceUrl, timeout, isOnline, mediaName, streamUrl)
Dim wmp
Dim isTimeout
Dim t
Set wmp = CreateObject("WMPlayer.OCX")
wmp.settings.autostart = False
wmp.url = sourceUrl
wmp.settings.volume = 0
wmp.controls.play
t = DateAdd("s", timeout, Now)
Do
isOnline = wmp.playState = 3
isTimeout = Now >= t
WScript.Sleep 5
Loop Until isOnline Or isTimeout
mediaName = wmp.currentMedia.Name
streamUrl = wmp.currentMedia.sourceUrl
wmp.controls.stop
End Sub
Sub forceCScriptExecution(title)
Dim arg, args, cmd
cmd = "%comspec% /K Title " & title &" & color 0A & "
If Not LCase(Right(WScript.FullName, 12)) = "\cscript.exe" Then
For Each arg In WScript.Arguments
If InStr(arg, " ") Then arg = """" & arg & """"
args = args & " " & arg
Next
CreateObject("WScript.Shell").Run _
cmd & "cscript //nologo """ & _
WScript.ScriptFullName & _
""" " & args
WScript.Quit
End If
End Sub

TCPClient iFix error: Invalid Operation at Current State 40020

This is a continuation of my last post: How to read weight from scale using ethernet connection
After creating the TCP connection in vb10 - I am now trying to read the weight from the scale in iFix (vb6). The code below works if I create a breakpoint and step through: strdata takes the weight of the scale (51g at the moment). However, when i simply run the code, I get the error:
Invalid operation at current state 40020.
What i think is happening is something to do with how quickly it reads or trying to read multiple times. Any tips would be great.
TCPclient is referring to winsock, and frmclient refers to my form. The command "S" is the necessary command for the scale to grab the weight value. Thanks!
Public Sub test()
On Error GoTo errHandler
Dim strData As String
frmClient.tcpClient.LocalPort = 0
frmClient.tcpClient.Connect "192.168.0.1", 8000
'Dim i As Integer
' For i = 0 To 2000
' Debug.Print "connection status=" & frmClient.tcpClient.State
' If frmClient.tcpClient.State = 7 Then
' Exit For Next i
frmClient.tcpClient.SendData "S" & vbCrLf
frmClient.tcpClient.GetData strData
MsgBox ("weight =" & strData)
'Exit Sub
errHandler:
MsgBox Err.Description & " " & Err.Number
'Resume Next
End Sub
Use the DataArrival event of your Winsock Control.
So something like:
' ... in your "frmClient" Form ...
Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
tcpClient.GetData strData, vbString
MsgBox ("weight =" & strData)
End Sub
*Obviously removing the GetData() call in your original test() method.
Got it working! The code is below. I created a picture sub to initialize the ports/IP at the beginning of the code execution and then to close the connection at the end. I made a timer to automatically read the weight upon stabilization, so the weight can be found by clicking the button, or simply waiting 2 seconds (2000ms). Best of luck and thanks for the help!
Public tcpC As New Winsock
Private Sub CFixPicture_Close()
tcpC.Close
End Sub
Private Sub CFixPicture_Initialize()
tcpC.LocalPort = 0
tcpC.Connect "192.168.0.1", 8000
End Sub
Private Sub CommandButton1_Click()
On Error GoTo errHandler
Dim strData As String
tcpC.SendData "S" & vbCrLf
tcpC.GetData strData
Text4.Caption = "Weight: " & strData
Exit Sub
errHandler:
MsgBox "error:" & Err.Description
End Sub
Private Sub readScale_OnTimeOut(ByVal lTimerId As Long)
Dim strData As String
tcpC.SendData "S" & vbCrLf
tcpC.GetData strData
Text4.Caption = "Weight: " & strData
Exit Sub
End Sub

Vbscript msxml12.XMLHTTP error handling

I use this vbscript code, to download web page:
Dim oXML
Set oXML = CreateObject("msxm12.XMLHTTP")
oXML.Open "GET", "mysite.com", False
oXML.Send
If there is no such web site, I get an error 80004005, Unspecified error at line "oXML.Open ..."
How can I handle this error in vbscript? I want to catch this error and show msgbox with my error, i.e. web page is not available.
There are at least three possible points of failure in your script.
CreateObject may fail; e.g. if you use msxml12 (digit 1) instead of msxml2 (letter l). Such blunders should be fixed during development.
.Open may fail; e.g. if you use "mysite.com" instead of a syntactically correct URL. If you get the URL at runtime, a 'look before you jump' check is advisable, an OERN can be used to catch bad URLs not found by your validation.
.Send may fail; e.g. if the site is down or abandoned. This is a clear case for an OERN.
The most important rule wrt OERN: Keep it local and short (Only one risky line between OERN and OEG0).
Demo code:
Option Explicit
Dim sUrl
For Each sUrl In Split("http://stackoverflow.com http://pipapo.org mysite.com")
Dim oXML, aErr
' Set oXML = CreateObject("msxm12.XMLHTTP")
Set oXML = CreateObject("msxml2.XMLHTTP.6.0")
On Error Resume Next
oXML.Open "GET", sUrl, False
aErr = Array(Err.Number, Err.Description)
On Error GoTo 0
If 0 = aErr(0) Then
On Error Resume Next
oXML.Send
aErr = Array(Err.Number, Err.Description)
On Error GoTo 0
Select Case True
Case 0 <> aErr(0)
WScript.Echo "send failed:", aErr(0), aErr(1)
Case 200 = oXML.status
WScript.Echo sUrl, oXML.status, oXML.statusText
Case Else
WScript.Echo "further work needed:"
WScript.Echo sUrl, oXML.status, oXML.statusText
End Select
Else
WScript.Echo "open failed:", aErr(0), aErr(1)
End If
Next
output:
cscript 24863986.vbs
http://stackoverflow.com 200 OK
send failed: -2146697211 The system cannot locate the resource specified.
open failed: -2147012890 System error: -2147012890.
But your problem is it's msxml2.http (El 2) not msxm12.http (1 2). Yopur error is because you dd not create the object sucessfully or test the object isn't empty.
The URL has to be 100% correct. Unlike a browser there is no code to fix urls.
The purpose of my program is to get error details.
How I get a correct URL is to type my url in a browser, navigate, and the correct URL is often in the address bar. The other way is to use Properties of a link etc to get the URL.
Also Microsoft.XMLHTTP maps to Microsoft.XMLHTTP.1.0. HKEY_CLASSES_ROOT\Msxml2.XMLHTTP maps to Msxml2.XMLHTTP.3.0. Try a later one
Try this way using xmlhttp. Edit the url's etc. If it seems to work comment out the if / end if to dump info even if seeming to work. It's vbscript but vbscript works in vb6.
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\test.txt", 2
Also see if these other objects work.
C:\Users>reg query hkcr /f xmlhttp
HKEY_CLASSES_ROOT\Microsoft.XMLHTTP
HKEY_CLASSES_ROOT\Microsoft.XMLHTTP.1.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.6.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.6.0
End of search: 12 match(es) found.
Also be aware there is a limit on how many times you can call any particular XMLHTTP object before a lockout occurs. If that happens, and it does when debugging code, just change to a different xmlhttp object

VBS To Event Log

I have a script that I am currently using to check when that network goes up or down. Its writing to a pinglog.txt .
For the life of me I can not figure out how to get it to write to the event log when the network goes down. Where it says:
Call logme(Time & " - " & machine & " is not responding to ping, CALL FOR
HELP!!!!",strLogFile)
Thats what I need to write to the Event Log "Machine is not repsonding to ping, CALL FOR HELP!!!!
'Ping multiple computers and log when one doesn't respond.
'################### Configuration #######################
'Enter the IPs or machine names on the line below separated by a semicolon
strMachines = "4.2.2.2;8.8.8.8;8.8.4.4"
'Make sure that this log file exists, if not, the script will fail.
strLogFile = "c:\logs\pinglog.txt"
'################### End Configuration ###################
'The default application for .vbs is wscript. If you double-click on the script,
'this little routine will capture it, and run it in a command shell with cscript.
If Right(WScript.FullName,Len(WScript.FullName) - Len(WScript.Path)) <> "\cscript.exe" Then
Set objWMIService = GetObject("winmgmts: {impersonationLevel=impersonate}!\\.\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
objProcess.Create WScript.Path + "\cscript.exe """ + WScript.ScriptFullName + """", Null, objConfig, intProcessID
WScript.Quit
End If
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strLogFile) Then
Set objFolder = objFSO.GetFile(strLogFile)
Else
Wscript.Echo "Log file does not exist. Please create " & strLogFile
WScript.Quit
End If
aMachines = Split(strMachines, ";")
Do While True
For Each machine In aMachines
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& machine & "'")
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<>0 Then
Call logme(Time & " - " & machine & " is not responding to ping, CALL FOR
HELP!!!!",strLogFile)
Else
WScript.Echo(Time & " + " & machine & " is responding to ping, we are good")
End If
Next
Next
WScript.Sleep 5000
Loop
Sub logme(message,logfile)
Set objTextFile = objFSO.OpenTextFile(logfile, ForAppending, True)
objtextfile.WriteLine(message)
WScript.Echo(message)
objTextFile.Close
End Sub
Sorry about the spacing in the code. Thanks for the help
Use the WshShell object:
object.LogEvent(intType, strMessage [,strTarget])
object WshShell object.
intType Integer value representing the event type.
strMessage String value containing the log entry text.
strTarget Optional. String value indicating the name of the computer
system where the event log is stored (the default is the local
computer system). Applies to Windows NT/2000 only.
Like so:
Option Explicit
Dim shl
Set shl = CreateObject("WScript.Shell")
Call shl.LogEvent(1,"Some Error Message")
Set shl = Nothing
WScript.Quit
The first argument to LogEvent is an event type:
0 SUCCESS
1 ERROR
2 WARNING
4 INFORMATION
8 AUDIT_SUCCESS
16 AUDIT_FAILURE
EDIT: more detail
Replace your entire 'logme' sub-routine with this
Sub logme(t,m)
Dim shl
Set shl = CreateObject("WScript.Shell")
Call shl.LogEvent(t,m)
Set shl = Nothing
End Sub
Then change this line:
Call logme(Time & " - " & machine & " is not responding to ping, CALL FOR HELP!!!!",strLogFile)
To:
Call logme(1, machine & " is not responding to ping, CALL FOR HELP!!!!")

winsock multiple IP senddata vb6

I have searching for a long time in different forums if it's possible to send a text to differents IP's using winsock but I can't find how.
I have try putting two different winsocks in the same form but the message of the second winsock never arrives.
This is my code:
Private Sub Form_Load()
On Error Resume Next
a = bytMsg()
wsck.RemoteHost = strNombreATMMonitor2
wsck.RemotePort = vPuertoATMMonitor2
wsck.Connect
'Conectamos el segundo
Winsock1.RemoteHost = strNombreATMMonitor
Winsock1.RemotePort = vPuertoATMMonitor
Winsock1.Connect
End Sub
Private Sub wsck_Close()
On Error Resume Next
wsck.Close
End
End Sub
Private Sub wsck_Connect()
On Error GoTo Err_wsck_Connect
wsck.SendData a
End_wsck_Connect:
Exit Sub
Err_wsck_Connect:
GrabaLog "wsck_Connect", Err.Description, " " & Err.Number & " Host: " & strNombreATMMonitor
Resume End_wsck_Connect
End Sub
Private Sub wsck_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)
'si no es un recordatorio, lo grabo
If bytRecordatorio = 0 Then
GrabaOff strLineaComandos
End If
GrabaLog "wsck_Error", "RemoteHost" & " - " & wsck.RemoteHost & " - RemotePort - " & Trim(wsck.RemotePort), "Error = " & Trim(Number) & " - " & Description
End
End Sub
Private Sub wsck_SendComplete()
On Error GoTo Err_wsck_SendComplete
wsck.Close
'Graba en un log el mensaje de NCR pasado como parametro a ATMSpyNEW + FTP
TrazaLog "ATMMonitor1 - " & strLineaComandos
End_wsck_SendComplete:
End
Err_wsck_SendComplete:
GrabaLog "wsck_SendComplete", Err.Description, "" & Err.Number
Resume End_wsck_SendComplete
End Sub
Private Sub Winsock1_Close()
On Error Resume Next
Winsock1.Close
End
End Sub
Private Sub Winsock1_Connect()
On Error GoTo Err_Winsock1_Connect
Winsock1.SendData a
End_Winsock1_Connect:
Exit Sub
Err_Winsock1_Connect:
GrabaLog "Winsock1_Connect", Err.Description, " " & Err.Number & " Host: " & strNombreATMMonitor
Resume End_Winsock1_Connect
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)
'si no es un recordatorio, lo grabo
If bytRecordatorio = 0 Then
GrabaOff strLineaComandos
End If
GrabaLog "Winsock1_Error", "RemoteHost" & " - " & Winsock1.RemoteHost & " - RemotePort - " & Trim(Winsock1.RemotePort), "Error = " & Trim(Number) & " - " & Description
End
End Sub
Does anybody knows how to send a piece of text to, at least, two different Ip's (RemoteHost) using one or two winsock controls?
I created a new VB6 project and added two Winsock controls onto the Form1. Namely Winsock1 and Winsock2. I then added two TextBoxes (for testing only to display input and output from the Winsocks) and set them to allow MultiLines. I added one button (cmdSendData) that will send data to both winsocks. In the Form_Load event, I made these two Winsocks connect to a common TelNet server that I already have access to (you will need to change the IP address to something you can test with). I was able to send data through both Winsocks (even though they are connected to the same machine, they behave separately and could easily change the IP of one of them to another if I knew that I have another IP waiting for a connection request).
I skipped the Error Handling since I am sure you can figure out where to put that.
Private Sub Form_Load()
Me.Winsock1.RemoteHost = "10.11.27.87"
Me.Winsock1.RemotePort = "23"
Me.Winsock1.Connect
Me.Winsock2.RemoteHost = "10.11.27.87"
Me.Winsock2.RemotePort = "23"
Me.Winsock2.Connect
End Sub
Private Sub cmdSendData_Click()
Me.Winsock1.SendData "admin" & vbCrLf
DoEvents 'This is necessary to immediatelly send the data without waiting for
' a certain buffer to be filled first
Me.Winsock2.SendData "admin" & vbCrLf
DoEvents 'same as above
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim txt As String
Me.Winsock1.GetData txt
Me.Text1.Text = Me.Text1.Text & vbCrLf & txt
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim txt As String
Me.Winsock2.GetData txt
Me.Text2.Text = Me.Text2.Text & vbCrLf & txt
End Sub

Resources