Bug? B4A Client socket fails using host name, works using IP address

Status
Not open for further replies.

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I am using B4A in client mode with a socket in B4A.

Connect To Server:
'============================================================================================
'============================================================================================
Private Sub btnWiFi_Click
    If WiFiConnected = False Then
'        mcuc.Initialize(Me, "shorttclock.local", 50000, 240000, 30000, 2000)
        mcuc.Initialize(Me, "tiny_shark",  51010, 240000, 30000, 2000)
'        mcuc.Initialize(Me, "192.168.1.132",  51010, 240000, 30000, 2000)
        Dim host As String = GetHostName("192.168.1.132")
        Log("Host = "& host)
    Else
        mcuc.socketClose
    End If
End Sub


Public Sub connectToServer
    Private clockSetData As clockSetData_t
    Do While mcuSockConnStatus = False
        setConnectionStatus(False)
        
        netErrorTimer.Enabled = False
        
        If tcpStream.IsInitialized Then
            tcpStream.Close
        End If
        
        If mcu_socket.IsInitialized Then
            mcu_socket.Close
        End If
        
        If mcu_socket.IsInitialized = False Then
            mcu_socket.Initialize("mcu_socket")
            mcu_socket.Connect(ipAddress, servPort, 0)
        End If
        
        Wait for mcu_socket_Connected(Successful As Boolean)
        
        If Successful Then
            #IF LOGGING_ON
            Log("Socket Event - MCU Socket OK")
            #END IF
            
            If tcpStream.IsInitialized Then
                tcpStream.Close
            End If
            
            setConnectionStatus(True)

            Sleep(500) 'Allow time for the server to ack connection on the MCU Interface
            
            If tcpStream.IsInitialized Then
                tcpStream.Close
            End If
            
            Try
                tcpStream.InitializePrefix(mcu_socket.InputStream, False, mcu_socket.OutputStream, "tcpStream")
                setConnectionStatus(True)
                clockSetData.clockMode = 0
                clockSetData.jogValue = 0
                clockSetData.jogRate = 0
                CallSub2(Main,"mcucsendCmd",clockSetData)
                Return
            Catch
                setConnectionStatus(False)
                'TODO    connectToServer
                #IF MIN_LOGGING_ON Or LOGGING_ON
                Log("TCP Stream Init Error")
                #END IF               
            End Try
            ' Set the command timer on if cmd queue is empty so we send null cmd to MCU
            mcuTranInProgress = False
        Else
            Sleep(500)
            #IF MIN_LOGGING_ON Or LOGGING_ON
            Log("Socket Event - MCU Socket Failed")
            #END IF
        End If
    Loop
End Sub

The socket fails to connect. If I provide the IP Address it works fine.

When I look at the output of GetHostName("192.168.1.132") it reports the IP address not the host name.

I am using the same code in B4J in the same application and it works fine.

The host server is an Inventek WiFi module and it uses mDNS to provide the local host name to the network router.

Do I have to prefix of suffix the host name to get it to work or is there some other problem.

Regards
Rob
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…