[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Reading Data from a specific port

i want to read data which is broadcast on port like 4010,4011,4012

guide me with code example
1 Solution
I think you'd have to create an application which uses a winsock application to listen on those ports, then accept the connection (and if there will me multiple messages broadcast at the same time, you need to use control arrays so that you can accept multiple connection simultaniously), then read through the data as it is received etc.  Unfortunately I dont have the time at the moment to build you an example sorry.

I can give you example code.. I just need to know if you want to make a server or a client.
pak_slmAuthor Commented:

i could not understand  server or client option. The environment is like we have two department. Other department have a programm name Gateway which broadcast some info like rate, symbol, type etc on a port. we run this programm on one computer. Now i want to read that info to use in the programm.
Jaime OlivaresCommented:
>i want to read data which is broadcast on port like 4010,4011,4012
I think you need a client application to receive UDP broadcasts.

insert a WinSock control into your main form and  name it listen4010, something like this:

Private Sub Form_Load()
    With listen4010
        .RemoteHost= "PeerB"   ' Name of the remote host
        .RemotePort = 4010  ' Port to connect to.
        .Bind 1001                ' Bind to the local port.
    End With
End Sub

Then you have to implement the reception function, something like

Private Sub listen4010_DataArrival (ByVal bytesTotal As Long)
    Dim data As String
    Dim msg As String
    listen4010.GetData data
    ' now data contains the frame received, but I guess data will be binary, so convert it to a 'readable' string
    For I = 0 to len(data)
         msg = msg & hex(asc(mid(data,I,1)))
    Next I
    MsgBox msg
End Sub

You will have to introduce more controls to listen more ports.

Some extra information at:

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now