TCP Clients connect, stream data is lost

Discussion in 'Visual Basic .Net' started by DN Admin, Apr 28, 2012.

  1. DN Admin

    Staff Member

    Country:
    United States
    Joined:
    Aug 7, 2010
    Location:
    Joliet, IL U.S.A.
    Connection succesfuly made (TCPClients)<br/>
    Writing/Reading with NetworkStream<br/>
    <br/>
    At an interval of 16 ms. <br/>
    <span class="x_x_Apple-tab-span" style="white-space:pre </span>Client sends 4 bytes -> Server receives 0 bytes ???<br/>
    <span class="x_x_Apple-tab-span" style="white-space:pre </span>Server Sends 4 bytes -> client receives 0 bytes ???<br/>
    <br/>
    Any idea why?<br/>
    <br/>
    Server code<br/>
    <br/>
    <pre class="prettyprint lang-vb Sub New(ByVal c As TcpClient, ByVal id As Byte)
    Client = c
    NS = Client.GetStream
    End Sub



    ' In a List -> In a Class -> Running in a BackgroundWorker

    Do

    Dim b(3) As Byte, blen As Int16 = 0

    NS.Read(b, 0, blen) ' blen is 0

    'Irelevant code deleted

    If Players.Count > 1 Then NS.Write(XmitData, 0, 4 * (Players.Count - 1)) Else NS.Write(New Byte() {0}, 0, 1) ' transmits 4 bytes

    Threading.Thread.Sleep(16)
    Loop While Client.Connected = True</pre>
    <br/>
    <br/>
    <span class="x_x_Apple-tab-span" style="white-space:pre </span><br/>
    Client Code<br/>
    <br/>

    <pre class="prettyprint lang-vb Public c As New TcpClient
    Dim NS As NetworkStream

    Sub New(ByVal ip As String)
    c.Connect(ip, 4)
    NS = c.GetStream
    End Sub

    'In a timer @ interval = 16 ms'

    Dim b(3) As Byte
    'irelevant code'
    NS.Write(b, 0, 4) ' b = {0,0,244,1}'

    Dim br(27) As Byte
    Dim blen As Integer
    NS.Read(br, 0, blen) ' blen = 0</pre>
    <br/>
    <br/>
    <br/>

    <

    <
    Muscalu Ștefan ~~~~ Student
    <

    <br/>

    View the full article
     
    #1

Share This Page