﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>A1VBCode Forums / Visual Basic .NET / .NET Programming  / Need Some Help with TCPClient NetworkStream Reading / Latest Posts</title><generator>InstantForum.NET v4.1.1</generator><description>A1VBCode Forums</description><link>http://www.a1vbcode.com/vbforums/</link><webMaster>forums@a1vbcode.com</webMaster><lastBuildDate>Thu, 09 Sep 2010 16:20:34 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Need Some Help with TCPClient NetworkStream Reading</title><link>http://www.a1vbcode.com/vbforums/Topic24998-9-1.aspx</link><description>Wow lol thats quite a hefty bit of code there...&lt;/P&gt;&lt;P&gt;I posted on another forum as well and got an even easier way to get the number of bytes from the network stream&lt;/P&gt;&lt;P&gt;EndRead() returns the number of bytes after reading a stream with the BeginStream() function.&lt;/P&gt;&lt;P&gt;Thanks for helping anyway...&lt;/P&gt;&lt;P&gt;&lt;img align="absmiddle" src="http://www.a1vbcode.com/vbforums/Skins/Classic/Images/EmotIcons/Wink.gif" border="0" title="Wink"&gt;</description><pubDate>Fri, 30 May 2008 07:37:14 GMT</pubDate><dc:creator>Daniel3120</dc:creator></item><item><title>RE: Need Some Help with TCPClient NetworkStream Reading</title><link>http://www.a1vbcode.com/vbforums/Topic24998-9-1.aspx</link><description>check this vb .net code.. I have downloaded it from net.. www.planetsourcecode.com&lt;br&gt;to ping ip add and check speed.. &lt;br&gt;=================================&lt;br&gt;Public Class frmMain&lt;br&gt;    Inherits System.Windows.Forms.Form&lt;br&gt;&lt;br&gt;#Region " Windows Form Designer generated code "&lt;br&gt;&lt;br&gt;    Public Sub New()&lt;br&gt;        MyBase.New()&lt;br&gt;&lt;br&gt;        'This call is required by the Windows Form Designer.&lt;br&gt;        InitializeComponent()&lt;br&gt;&lt;br&gt;        'Add any initialization after the InitializeComponent() call&lt;br&gt;&lt;br&gt;    End Sub&lt;br&gt;&lt;br&gt;    'Form overrides dispose to clean up the component list.&lt;br&gt;    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)&lt;br&gt;        If disposing Then&lt;br&gt;            If Not (components Is Nothing) Then&lt;br&gt;                components.Dispose()&lt;br&gt;            End If&lt;br&gt;        End If&lt;br&gt;        MyBase.Dispose(disposing)&lt;br&gt;    End Sub&lt;br&gt;&lt;br&gt;    'Required by the Windows Form Designer&lt;br&gt;    Private components As System.ComponentModel.IContainer&lt;br&gt;&lt;br&gt;    'NOTE: The following procedure is required by the Windows Form Designer&lt;br&gt;    'It can be modified using the Windows Form Designer.  &lt;br&gt;    'Do not modify it using the code editor.&lt;br&gt;    Friend WithEvents btnCheck As System.Windows.Forms.Button&lt;br&gt;    Friend WithEvents txtAddress As System.Windows.Forms.TextBox&lt;br&gt;    Friend WithEvents lblSuccess As System.Windows.Forms.Label&lt;br&gt;    Friend WithEvents lblTime As System.Windows.Forms.Label&lt;br&gt;    Friend WithEvents lblDown As System.Windows.Forms.Label&lt;br&gt;    Friend WithEvents lblUp As System.Windows.Forms.Label&lt;br&gt;    Friend WithEvents lblAddress As System.Windows.Forms.Label&lt;br&gt;    Friend WithEvents lblNetwork As System.Windows.Forms.Label&lt;br&gt;    &lt;System.Diagnostics.DebuggerStepThrough()&gt; Private Sub InitializeComponent()&lt;br&gt;        Me.btnCheck = New System.Windows.Forms.Button&lt;br&gt;        Me.lblTime = New System.Windows.Forms.Label&lt;br&gt;        Me.txtAddress = New System.Windows.Forms.TextBox&lt;br&gt;        Me.lblAddress = New System.Windows.Forms.Label&lt;br&gt;        Me.lblDown = New System.Windows.Forms.Label&lt;br&gt;        Me.lblUp = New System.Windows.Forms.Label&lt;br&gt;        Me.lblSuccess = New System.Windows.Forms.Label&lt;br&gt;        Me.lblNetwork = New System.Windows.Forms.Label&lt;br&gt;        Me.SuspendLayout()&lt;br&gt;        '&lt;br&gt;        'btnCheck&lt;br&gt;        '&lt;br&gt;        Me.btnCheck.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))&lt;br&gt;        Me.btnCheck.Location = New System.Drawing.Point(176, 64)&lt;br&gt;        Me.btnCheck.Name = "btnCheck"&lt;br&gt;        Me.btnCheck.Size = New System.Drawing.Size(304, 24)&lt;br&gt;        Me.btnCheck.TabIndex = 0&lt;br&gt;        Me.btnCheck.Text = "Check the Specified Address"&lt;br&gt;        '&lt;br&gt;        'lblTime&lt;br&gt;        '&lt;br&gt;        Me.lblTime.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle&lt;br&gt;        Me.lblTime.Location = New System.Drawing.Point(176, 24)&lt;br&gt;        Me.lblTime.Name = "lblTime"&lt;br&gt;        Me.lblTime.Size = New System.Drawing.Size(304, 16)&lt;br&gt;        Me.lblTime.TabIndex = 1&lt;br&gt;        Me.lblTime.Text = "Time to Reach and Return Data:"&lt;br&gt;        '&lt;br&gt;        'txtAddress&lt;br&gt;        '&lt;br&gt;        Me.txtAddress.Location = New System.Drawing.Point(8, 64)&lt;br&gt;        Me.txtAddress.Name = "txtAddress"&lt;br&gt;        Me.txtAddress.Size = New System.Drawing.Size(152, 20)&lt;br&gt;        Me.txtAddress.TabIndex = 2&lt;br&gt;        Me.txtAddress.Text = "www.vbcodesource.com"&lt;br&gt;        '&lt;br&gt;        'lblAddress&lt;br&gt;        '&lt;br&gt;        Me.lblAddress.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))&lt;br&gt;        Me.lblAddress.Location = New System.Drawing.Point(8, 8)&lt;br&gt;        Me.lblAddress.Name = "lblAddress"&lt;br&gt;        Me.lblAddress.Size = New System.Drawing.Size(160, 56)&lt;br&gt;        Me.lblAddress.TabIndex = 3&lt;br&gt;        Me.lblAddress.Text = "Address to Check/Reach/Ping. You can use IP/URL address or UNC name."&lt;br&gt;        '&lt;br&gt;        'lblDown&lt;br&gt;        '&lt;br&gt;        Me.lblDown.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle&lt;br&gt;        Me.lblDown.Location = New System.Drawing.Point(176, 40)&lt;br&gt;        Me.lblDown.Name = "lblDown"&lt;br&gt;        Me.lblDown.Size = New System.Drawing.Size(152, 16)&lt;br&gt;        Me.lblDown.TabIndex = 4&lt;br&gt;        Me.lblDown.Text = "Down Speed:"&lt;br&gt;        '&lt;br&gt;        'lblUp&lt;br&gt;        '&lt;br&gt;        Me.lblUp.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle&lt;br&gt;        Me.lblUp.Location = New System.Drawing.Point(328, 40)&lt;br&gt;        Me.lblUp.Name = "lblUp"&lt;br&gt;        Me.lblUp.Size = New System.Drawing.Size(152, 16)&lt;br&gt;        Me.lblUp.TabIndex = 5&lt;br&gt;        Me.lblUp.Text = "Up Speed:"&lt;br&gt;        '&lt;br&gt;        'lblSuccess&lt;br&gt;        '&lt;br&gt;        Me.lblSuccess.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle&lt;br&gt;        Me.lblSuccess.Location = New System.Drawing.Point(176, 8)&lt;br&gt;        Me.lblSuccess.Name = "lblSuccess"&lt;br&gt;        Me.lblSuccess.Size = New System.Drawing.Size(192, 16)&lt;br&gt;        Me.lblSuccess.TabIndex = 6&lt;br&gt;        Me.lblSuccess.Text = "Successful:"&lt;br&gt;        '&lt;br&gt;        'lblNetwork&lt;br&gt;        '&lt;br&gt;        Me.lblNetwork.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle&lt;br&gt;        Me.lblNetwork.Location = New System.Drawing.Point(280, 8)&lt;br&gt;        Me.lblNetwork.Name = "lblNetwork"&lt;br&gt;        Me.lblNetwork.Size = New System.Drawing.Size(200, 16)&lt;br&gt;        Me.lblNetwork.TabIndex = 7&lt;br&gt;        Me.lblNetwork.Text = "Network Type Used:"&lt;br&gt;        '&lt;br&gt;        'frmMain&lt;br&gt;        '&lt;br&gt;        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)&lt;br&gt;        Me.ClientSize = New System.Drawing.Size(490, 96)&lt;br&gt;        Me.Controls.Add(Me.lblNetwork)&lt;br&gt;        Me.Controls.Add(Me.lblSuccess)&lt;br&gt;        Me.Controls.Add(Me.lblUp)&lt;br&gt;        Me.Controls.Add(Me.lblDown)&lt;br&gt;        Me.Controls.Add(Me.lblAddress)&lt;br&gt;        Me.Controls.Add(Me.txtAddress)&lt;br&gt;        Me.Controls.Add(Me.lblTime)&lt;br&gt;        Me.Controls.Add(Me.btnCheck)&lt;br&gt;        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow&lt;br&gt;        Me.MaximizeBox = False&lt;br&gt;        Me.Name = "frmMain"&lt;br&gt;        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen&lt;br&gt;        Me.Text = "  Check if Web Address is Available using API - 2002/2003"&lt;br&gt;        Me.ResumeLayout(False)&lt;br&gt;&lt;br&gt;    End Sub&lt;br&gt;&lt;br&gt;#End Region&lt;br&gt;    '&lt;br&gt;    '&lt;br&gt;    'The type of network the API used to reach its destination.&lt;br&gt;    Enum networkType&lt;br&gt;&lt;br&gt;        Lan_Network = 1&lt;br&gt;        Wan_Network = 2&lt;br&gt;        Aol_Network = 4 'This is pretty much obsolete since it would only be used with Win 95/98.&lt;br&gt;        No_Network = 0&lt;br&gt;&lt;br&gt;    End Enum&lt;br&gt;    '&lt;br&gt;    '&lt;br&gt;    'This structure is passed to the 2nd parameter in the isDestination API call ByReference since&lt;br&gt;    'the API will Put info IN the Structure and NOT read data FROM the structure.&lt;br&gt;    Private Structure qocStructure&lt;br&gt;        '&lt;br&gt;        'Used to specifiy the structure's size. The API call will use this value first when you&lt;br&gt;        'call to get the size of the structure being used, and then it will set this value to &lt;br&gt;        'the size of the structure with the data in the structure.&lt;br&gt;        Dim structureSize As Int32&lt;br&gt;        '&lt;br&gt;        'Will hold the value for the type of network.&lt;br&gt;        Dim networkFlags As networkType&lt;br&gt;        '&lt;br&gt;        'Will contain the speed in bytes per second coming from the destination.&lt;br&gt;        Dim inSpeed As Int32&lt;br&gt;        '&lt;br&gt;        'Will contain the speed in bytes per second going to the destination.&lt;br&gt;        Dim outSpeed As Int32&lt;br&gt;&lt;br&gt;    End Structure&lt;br&gt;    '&lt;br&gt;    'The API call to get the info we want. This API function is NOT supported by the Windows Vista&lt;br&gt;    'Operating System. The destination address can be a URL Address, IP Address, or UNC &lt;br&gt;    '(Universal Naming Convention) name.&lt;br&gt;    Private Declare Function IsDestinationReachable Lib "sensapi.dll" Alias _&lt;br&gt;        "IsDestinationReachableA" (ByVal destinationAddress As String, ByRef qocInfoStructure _&lt;br&gt;            As qocStructure) As Int32&lt;br&gt;    '&lt;br&gt;    '&lt;br&gt;    Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click&lt;br&gt;        '&lt;br&gt;        'Will hold the return value of the API call.&lt;br&gt;        Dim pingSuccess As Int32&lt;br&gt;        '&lt;br&gt;        'Create a variable for the Quality of Connection structure.&lt;br&gt;        Dim qoc As qocStructure&lt;br&gt;        '&lt;br&gt;        'Specify the size of this structure for the API call to read.&lt;br&gt;        qoc.structureSize = Len(qoc)&lt;br&gt;        '&lt;br&gt;        'Get the tick value before calling the API.&lt;br&gt;        Dim tickStart As Integer = Environment.TickCount&lt;br&gt;        '&lt;br&gt;        '&lt;br&gt;        'Call the API passing the address in the textbox control.&lt;br&gt;        pingSuccess = IsDestinationReachable(txtAddress.Text, qoc)&lt;br&gt;&lt;br&gt;        '&lt;br&gt;        '&lt;br&gt;        'Get the value after the call.&lt;br&gt;        Dim tickEnd As Integer = Environment.TickCount&lt;br&gt;        '&lt;br&gt;        'Now get the total milli-seconds it took to call the API function and reach the network.&lt;br&gt;        Dim ticks As Integer = (tickEnd - tickStart)&lt;br&gt;        '&lt;br&gt;        '&lt;br&gt;        'Check if the address was able to be reached before going displaying anymore data.&lt;br&gt;        If pingSuccess = 1 Then&lt;br&gt;            '&lt;br&gt;            'Display "True" since the value was '1'.&lt;br&gt;            lblSuccess.Text = "Successful: True"&lt;br&gt;&lt;br&gt;        ElseIf pingSuccess = 0 Then&lt;br&gt;            '&lt;br&gt;            'Display "False" since the value was '0'.&lt;br&gt;            lblSuccess.Text = "Successful: False"&lt;br&gt;&lt;br&gt;        Else&lt;br&gt;            '&lt;br&gt;            'If the return value is not 0 or 1 then the api call failed. It would most likely be&lt;br&gt;            '-1 which means the api call failed.&lt;br&gt;            '&lt;br&gt;            'Display "Actual Call Failed" since the value was not '0 or 1'.&lt;br&gt;            lblSuccess.Text = "Successful: API Call Failed"&lt;br&gt;&lt;br&gt;        End If&lt;br&gt;        '&lt;br&gt;        'Display the time to call the API call. This is really not that important since the API&lt;br&gt;        'will also get the up and down speed of the connection before getting back to use. So &lt;br&gt;        'this will NOT be the actual ping time to check the address.&lt;br&gt;        lblTime.Text = "Time to Reach and Return Data: " &amp; ticks.ToString &amp; " ms"&lt;br&gt;        '&lt;br&gt;        'Display the UP/Down speed of the connection to reach the network.&lt;br&gt;        '&lt;br&gt;        lblDown.Text = "Down Speed: " &amp; (qoc.inSpeed / 1000000).ToString &amp; " mbps"&lt;br&gt;        lblUp.Text = "Up Speed: " &amp; (qoc.outSpeed / 1000000).ToString &amp; " mbps"&lt;br&gt;        '&lt;br&gt;        'Display the network used.&lt;br&gt;        lblNetwork.Text = "Network Type Used: " &amp; qoc.networkFlags.ToString&lt;br&gt;&lt;br&gt;    End Sub&lt;br&gt;&lt;br&gt;End Class&lt;br&gt;&lt;br&gt;=================================</description><pubDate>Fri, 30 May 2008 07:13:32 GMT</pubDate><dc:creator>smyle22</dc:creator></item><item><title>Need Some Help with TCPClient NetworkStream Reading</title><link>http://www.a1vbcode.com/vbforums/Topic24998-9-1.aspx</link><description>&lt;DIV id=post_message_80622&gt;At the minute when i try to read from the TCPClient NetworkStream, I have no way to set the read buffer to the correct amount of data being received on the stream. &lt;BR&gt;&lt;BR&gt;I have tried using TCPClient.Client.ReceiveBufferSize but this is always 8192 even if the data being received is less than that.&lt;BR&gt;&lt;BR&gt;It is important because i end up with a load of 0 bytes at the end of the buffer which is causing me a lot of problems. &lt;IMG class=inlineimg title=Mad alt="" src="http://www.vbdotnetforums.com/images/smilies/mad.gif" border=0&gt;&lt;BR&gt;&lt;BR&gt;Does anyone have any ideas on how to get it to set the buffer to the correct size? heres my code so far, its running on a different thread to TCP:&lt;BR&gt;&lt;BR&gt;Private Sub Listen()&lt;BR&gt;Try&lt;BR&gt;Do Until nolisten = True&lt;BR&gt;&lt;BR&gt;Do Until ns.DataAvailable&lt;BR&gt;'wait until data available or disconnected&lt;BR&gt;Loop&lt;BR&gt;&lt;BR&gt;errtimeout.Stop()&lt;BR&gt;&lt;BR&gt;If ns.DataAvailable Then&lt;BR&gt;Dim size As Integer = TCP.Client.ReceiveBufferSize&lt;BR&gt;Dim b(size) As Byte&lt;BR&gt;'ns.Read(b, 0, size)&lt;BR&gt;ns.BeginRead(b, 0, size, New AsyncCallback(AddressOf nsread), b)&lt;BR&gt;End If&lt;BR&gt;&lt;BR&gt;Loop&lt;BR&gt;Catch ex As ObjectDisposedException&lt;BR&gt;End Try&lt;BR&gt;End Sub&lt;/DIV&gt;</description><pubDate>Fri, 23 May 2008 06:39:53 GMT</pubDate><dc:creator>Daniel3120</dc:creator></item></channel></rss>