Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Question about end point IP and buffer
bradbritton

From: Red Deer, AB Canada
Posts: 14
Member Since: 02/09/06
posted May 11, 2006 4:52 PM

I am using the following code to listen for incoming data. The code works great if the first bytes in is not a zero, but if it is it will not work. The questions I have are this:

1. How can I get the address of the incoming data?

2. Is there a better way to compare the data in the buffer?

Thanks,

Brad

Try
        'Sends command for data to the unit
        sendCommand()
        ' resizes bytes so that it is able to accept the data
        ReDim bytes(511)
        ' sets the incoming buffer to the correct size for the page data
        Udp1.BufferSize = 511
        '' waits to receive the data from the logger
        Udp1.Receive(bytes, 0, 511, SocketFlags.None


      Catch ex As Exception

      Finally
        ' data = the incoming page, converted via the BytesToHex function
        'data = BytesToHex(bytes)

        ' Enters IF loop only if the first btye of data in the buffer is not Zero(0)
        If bytes(0) <> Nothing Then
          'TextBox1.Text = data ' displays data in Textbox

          hexIncrement() ' Increments the page for the next send command

          'Inserts data into the database

          dataAdapter.Insert(rdlDataSet.Tables("WELL").Rows(cbModem.SelectedIndex).Item("TOOL_IP").ToString, bytes, bytes.Length, System.DateTime.UtcNow.ToUniversalTime, pageno, rdlDataSet.Tables("WELL").Rows(cbModem.SelectedIndex).Item("WELL_SERIAL"))
          'Updates the dataAdapter for the RemoteDataLogger Dataset
          dataAdapter.Update(rdlDataSet.DATA)
          'Accepts the changes to the database
          rdlDataSet.AcceptChanges()
          'sets bytes to (0) Zero so that it will not enter the IF loop by mistake
          bytes = Nothing

        End If

      End Try
Raj

From: Rome, NY, USA
Posts: 389
Member Since: 02/01/06
posted May 15, 2006 4:16 PM

Hi Brad,

1. How can I get the address of the incoming data?
If you use Udp.EndReceive Event, it returns a Datagram object. This Datagram object has a Datagram.RemoteEndPoint Property, which gives the address of the incoming data.

2. Is there a better way to compare the data in the buffer?
Please refer the following Microsoft newsgroup search result, which discusses different ways of comparing byte arrays:
http://msdn.microsoft.com/newsgroups/default.aspx?query=Comparing+byte+arrays&dg=&cat=en-us-msdn&lang=en&cr=US&pt=&catlist=774F24A2-F71F-425F-AC2B-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us

When you say that your code does not work if first byte is zero, have you tried debugging it, to find what causes you code to break.

-Raj
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX