In VBA Pairing Hostname & Port (1 Viewer)

nectorch

Member
Local time
Today, 11:56
Joined
Aug 4, 2021
Messages
41
Dear all;

See if you can guide here

(1) My understanding of the hostname is the local name of the machine or IP address which we get it by "netstart an" on the CMD prompt. Now when sending serial data to the other device on the same network which one of the pairs do we use?

(1) Hostname; Port number (All from source)
(2) Hostname (local) : port number ( destination)

For example in the VBA parameters below how do we go about it?


Code:
Public Function ConnectServer(ByVal Hostname As String, ByVal PortNumber As Integer) As Integer

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

Dim I_SocketAddress As sockaddr_in
Dim ipAddress As Long
ipAddress = inet_addr(Hostname) '...........(1)
'Create a new socket
socketId = socket(AF_INET, SOCK_STREAM, 0) '
If socketId = SOCKET_ERROR Then '
MsgBox ("ERROR: socket = " + Str$(socketId)) '...........(2)
OpenSocket = COMMAND_ERROR '
GoTo end1
End If '
'Open a connection to a server
I_SocketAddress.sin_family = AF_INET '
I_SocketAddress.sin_port = htons(PortNumber) '...........(3)
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)) '..(4)
        OpenSocket = COMMAND_ERROR '
    Else
        OpenSocket = socketId
End If
end1:
End Function[CODE]




Any assistance will be highly appreciated

Call ConnectServer("IP Address": Port Number)
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:56
Joined
May 7, 2009
Messages
19,169
are you using the code from msAccess?
does the other computer has msAccess?
if both are true, why not use "simple messaging" sender send a message.
and the recipient, having a timer event on the form, waits for the message.
the message is not really sent. it is stored on a table in "shared database".

i have never seen a working x64 vba winsock. and the direction of ms office
is going to x64 bit.

Solved - Send message to specific user in access multi user based system | Access World Forums (access-programmers.co.uk)
 
Last edited:

nectorch

Member
Local time
Today, 11:56
Joined
Aug 4, 2021
Messages
41
are you using the code from msAccess?
does the other computer has msAccess?

No the other computer is a serial gadget not a computer
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:56
Joined
May 7, 2009
Messages
19,169
serial gadget
then read it's Manual on how to use vba/vbscript on how to send/received data.
it is not enough that you open the port/ip and wait for signal.
you need to "send" some initialization code to the serial port first.
 

nectorch

Member
Local time
Today, 11:56
Joined
Aug 4, 2021
Messages
41
there is a Serial port code here maybe it will help you with your quest:

Ok this is the current one I'm using and works very well after some adjustments with the cutting & buffer adjustment it is all nice but the serial port cannot be shared by multiple users unless one buys a port redirector at $2500.00 which is too expensive. This is the reason why I need to try also the socket method, I have not included the long module here because I have no issues on the following:

(1) Send data command
(2) Receive data command
(3) Cleaning up & closing

The issue is opening the socket ID , here what I mean by socket Id = ( IP Address +Port number). I'm not too sure with parameters to use , should it be hostname (Source) + Port Number (Source) or Hostname (Destination) + Port number (Destination) ??????????

Regards

Chris
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:56
Joined
May 7, 2009
Messages
19,169
did you try ip\port, eg:

192.168.1.5:888
 

nectorch

Member
Local time
Today, 11:56
Joined
Aug 4, 2021
Messages
41
I will try it , I hope this will help but I'm almost there, because I'm able to ping the gadget from a remote work station , for curiosity does

192.168.1.5 represent the Hostname ?????????
8888 represent destination gadget port ??????
 

Users who are viewing this thread

Top Bottom