troubleshooting Question

How to determine whether Winsock is part of Windows 10

Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia asked on
Windows 10Microsoft AccessWindows OSVBA
6 Comments2 Solutions20 ViewsLast Modified:
After working very hard with VBA for Winsock , I have come to realize that actually this WinSock API, is just a Library which is supposed to reside in windows.

How do I know whether my O/S has Winsock?

If nothing can get it somewhere?

The code below appear not function either due the above issue:

Option Compare Database


Option Explicit




Public Const COMMAND_ERROR = -1
Public Const RECV_ERROR = -1
Public Const NO_ERROR = 0
Public socketId As Long
'Global Variables for WINSOCK
Global State As Integer


Sub CloseConnection()
Dim x As Long
' we close our connection here
    x = closesocket(socketId)
    If x = SOCKET_ERROR Then
        MsgBox ("ERROR: closesocket = " + Str$(x))
        Exit Sub
    End If
End Sub


Sub EndIt()
Dim x As Long
    'Shutdown Winsock DLL
    x = WSACleanup()
End Sub




Function OpenSocket(ByVal Hostname As String, ByVal PortNumber As Integer) As Integer
   
    Dim I_SocketAddress As sockaddr_in
    Dim ipAddress As Long
    Dim x As Long
   
    ipAddress = inet_addr(Hostname)


    'Create a new socket
    socketId = socket(AF_INET, SOCK_STREAM, 0)
    If socketId = SOCKET_ERROR Then
        MsgBox ("ERROR: socket = " + Str$(socketId))
        OpenSocket = COMMAND_ERROR
        Exit Function
    End If


    'Open a connection to a server
    I_SocketAddress.sin_family = AF_INET
    I_SocketAddress.sin_port = htons(PortNumber)
    I_SocketAddress.sin_addr = ipAddress
    I_SocketAddress.sin_zero = String$(8, 0)


    x = connect(socketId, I_SocketAddress, Len(I_SocketAddress))
    If socketId = SOCKET_ERROR Then
        MsgBox ("ERROR: connect = " + Str$(x))
        OpenSocket = COMMAND_ERROR
        Exit Function
    End If
    OpenSocket = socketId
End Function


Function SendCommand(ByVal command As String) As Integer
' our communication command...


    Dim strSend As String
    Dim count As Long
   
    strSend = command + vbCrLf
   
    count = send(socketId, ByVal strSend, Len(strSend), 0)
   
    If count = SOCKET_ERROR Then
        MsgBox ("ERROR: send = " + Str$(count))
        SendCommand = COMMAND_ERROR
        Exit Function
    End If
   
    SendCommand = NO_ERROR


End Function


Function RecvAscii(dataBuf As String, ByVal maxLength As Integer) As Integer
On Error GoTo Error_Handler
DoEvents
Dim c As String * 12288
Dim length As Integer


dataBuf = ""
DoEvents
dataBuf = recv(socketId, c, 12288, 0)
dataBuf = c
length = Len(dataBuf)


Exit Function
Error_Handler:
DoEvents
MsgBox Err.Number & " " & Err.Description
DoEvents


End Function


Function StartIt()
Dim StartUpInfo As WSAData
Dim Version As Integer
Dim x As Long
'Version 1.1 (1*256 + 1) = 257
'version 2.0 (2*256 + 0) = 512
'Get WinSock version
Version = (1 * 256 + 1)
'Initialize Winsock DLL
x = WSAStartup(Version, StartUpInfo)
End Function

Open in new window


ASKER CERTIFIED SOLUTION
Pavel Celba
All in One

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 6 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 6 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004