Write to tcpclient stream hangs


Active member
Jun 21, 2007
Programming Experience
Hey all,

I hope this is the right thread.

I am working on an application which will run on windows ce 6.0.

It will receive data on serial port, and store it to a cf card plus forward it to network.

Now I have never done anything with network so I am a total rookie, but I searched internet and forums and found this article Client Server Multithreading Application
which I modified to what I need.
At my client side(application on device) I have this part of code:
  Dim trdNetConnect As Thread
    Dim trdNetConnectIsRunning As Boolean = False
    Dim ipAddress As String = ""
    Dim portNumber As Integer = 8002

    Public Sub startServer()
        trdNetConnectIsRunning = True
        tcpclnt = New TcpClient()
                tcpclnt.Connect(ipAddress.Trim(), portNumber)
                stm = tcpclnt.GetStream()
                eth_conn = True
                trdNetConnectIsRunning = False
                Exit Do
            Catch ex As Exception
                eth_conn = False
            End Try
    End Sub 'startServer
 Public Sub writeToServer(ByVal strn As String)
        Dim encord As New System.Text.ASCIIEncoding()
        Dim state As New StateObj
        writeBuffer = encord.GetBytes(strn)
        If Not (stm Is Nothing) Then
                'stm.BeginWrite(writeBuffer, 0, writeBuffer.Length, New AsyncCallback(AddressOf ), state)
                stm.Write(writeBuffer, 0, writeBuffer.Length)
                _Frm_Main.UpdateTextBox1("write out")
            Catch ex As Exception
                eth_conn = False
            End Try
        End If
    End Sub 'writeToServer

Well the problem is that stm.write hangs. Would anyone know why.
Is there a better way to achive this, I only need to forward data to a server. For now server won't send anything to client.

Thanks for help.

Top Bottom