troubleshooting Question

Window defender blocking Winsock from communicating in Ms Access

Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia asked on
* microsoft defenderMicrosoft AccessWindows XPNetworkingAnti-Virus Apps
1 Comment1 Solution9 ViewsLast Modified:
After working with VBA code below to try and send data to the serial gadget, now the communication is being blocked by window defender. Could it the VBA code below I have made a mistake somewhere?

To start the winisock I 'm calling the function below:

Call main

Open in new window


To send and receive data I'm calling the function below:

Call getStringFromSocket (strData)

Open in new window

Main Functions require your checking:

Option Compare Database


Option Explicit


Sub main() ' {


    If Not initWinsock Then
       MsgBox "Could not initialize Winsock"
    End If


    Debug.Print "winsock initialized"


    Dim serverSocket As Long
    serverSocket = createServerSocket(8888)


    acceptConnections serverSocket


    closesocket serverSocket
    WSACleanup


End Sub ' }


Function createServerSocket(ByVal port As Long) ' {


    createServerSocket = socket(AF_INET, SOCK_STREAM, 0)


    Dim endPoint As sockaddr_in
    endPoint.sin_family = AF_INET
    endPoint.sin_addr.s_addr = INADDR_ANY
    endPoint.sin_port = htons(port)


'   debug.print "lenB: " & lenB(endPoint)


    Dim rc As Long
    rc = bind(createServerSocket, endPoint, 16)
    If rc <> 0 Then
       MsgBox "Could not bind, error = " & WSAGetLastError()
       Exit Function
    End If


    rc = listen(createServerSocket, 10) ' 10 = backlog
    If rc <> 0 Then
       MsgBox "Could not listen"
    End If


End Function ' }


Sub acceptConnections(serverSocket As Long) ' {


    Dim clientSocket As Long


    Dim i As Long
    i = 0


    Do While i < 200
       i = i + 1
       Sleep 100
       Debug.Print "i = " & i


       clientSocket = getClientSocket(serverSocket)


       If clientSocket = 0 Then
          GoTo SKIP_THIS_ITERATION
       End If


       Dim reqText As String
       reqText = getStringFromSocket(clientSocket)


       Dim textResponse As String
       textResponse = "HTTP/1.1 200 OK" & Chr(10)
       textResponse = textResponse & "Content-Type: text/html" & Chr(10)
       textResponse = textResponse & Chr(10)
       textResponse = textResponse & "<!doctype html>" & Chr(10)
       textResponse = textResponse & "<html><body>Request was:<br><code><pre>"
       textResponse = textResponse & reqText
       textResponse = textResponse & "</pre></code></body></html>"


       send clientSocket, ByVal textResponse, Len(textResponse), 0


       closesocket clientSocket


SKIP_THIS_ITERATION:
    Loop


End Sub ' }


Function getClientSocket(serverSocket As Long) As Long ' {
    Dim fdSet As fd_set
    Dim emptyFdSet As fd_set
    Dim rc         As Integer


    FD_ZERO fdSet
    FD_SET_ serverSocket, fdSet


    Dim timeOutMs As Long
    timeOutMs = 500


    Dim timeOut  As timeval
    timeOut.tv_sec = timeOutMs / 1000
    timeOut.tv_usec = timeOutMs Mod 1000


    rc = select_(serverSocket, fdSet, emptyFdSet, emptyFdSet, timeOut)
    If rc = 0 Then
       getClientSocket = 0
       Exit Function
    End If


    Dim socketAddress As sockaddr
    getClientSocket = accept(serverSocket, socketAddress, 16)


    If getClientSocket = -1 Then
       getClientSocket = 0
       Exit Function
    End If


    rc = setsockopt(getClientSocket, SOL_SOCKET, SO_RCVTIMEO, timeOutMs, 4)


End Function ' }


Function getStringFromSocket(s As Long) ' {
    Dim message   As String
    Dim buffer    As String * 1024
    Dim readBytes As Long


    message = ""


    Do
        buffer = ""
        readBytes = recv(s, buffer, Len(buffer), 0)


        If readBytes > 0 Then
           message = message & Trim(buffer)
        End If
    Loop While readBytes > 0


    getStringFromSocket = Trim(message)


End Function ' }


Function initWinsock() As Boolean ' {


    Dim wsaVersion As Long
        wsaVersion = 257




    Dim rc  As Long
    Dim wsa As WSADATA


    rc = WSAStartup(wsaVersion, wsa)


    If rc <> 0 Then
       initWinsock = False
       Exit Function
    End If


    initWinsock = True


End Function ' }

Open in new window

How about the IP address how do I bring it in , the port number  " 8888" is lready hard coded?
ASKER CERTIFIED SOLUTION
Jonathan Kelly

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 1 Answer and 1 Comment.
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 1 Answer and 1 Comment.
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