Click here to Skip to main content
15,894,825 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB Operating System Pin
Bert Mitton25-Oct-11 5:38
professionalBert Mitton25-Oct-11 5:38 
GeneralRe: VB Operating System Pin
Paul Conrad25-Oct-11 5:48
professionalPaul Conrad25-Oct-11 5:48 
AnswerRe: VB Operating System Pin
Richard Andrew x6425-Oct-11 5:49
professionalRichard Andrew x6425-Oct-11 5:49 
AnswerRe: VB Operating System PinPopular
Richard MacCutchan25-Oct-11 6:05
mveRichard MacCutchan25-Oct-11 6:05 
AnswerRe: VB Operating System Pin
Smithers-Jones26-Oct-11 12:11
Smithers-Jones26-Oct-11 12:11 
GeneralRe: VB Operating System Pin
VOT Productions3-Nov-11 12:01
VOT Productions3-Nov-11 12:01 
AnswerRe: VB Operating System Pin
biop.codeproject13-Nov-11 17:08
biop.codeproject13-Nov-11 17:08 
QuestionTCP Socket client communication without using a buffer Pin
comiteco24-Oct-11 12:33
comiteco24-Oct-11 12:33 
Hello:

I´m using TCP client socket in my app. In this case I need to receive data from a device (that is working as TCP server) that is continuosly sending messages without specifying the lenght of the sent data before sending it, it´s like a streaming of binary data. I need to read this data and process some specific parts of the message. The most common references I found about receiving TCP data is using the Stream Read method, but this method requires to define a buffer of defined size. Please read my code below:

VB
Imports System.IO
Imports System.Net.Sockets
Imports System.Threading
Imports System.Net
Imports System.Text

Public Class Write
    Public Event DataRecieved(ByVal data As String)
    Private Stm As Stream
    Private tcpThd As Thread


    Public Sub ConnectToServer()
        Try
            Dim tcpClnt As New TcpClient
            tcpClnt.Connect(IPAddress.Parse("192.168.1.50"), 2111)
            Stm = tcpClnt.GetStream()
            tcpThd = New Thread(AddressOf ReadSocket)
            tcpThd.Start()
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

    End Sub

#Region "Private Methods"
    Private Sub ReadSocket()
        Dim Buffer() As Byte
        While True
            Buffer = New Byte(4000) {}
            Stm.Read(Buffer, 0, Buffer.Length)
            DataRecieved(Encoding.ASCII.GetString(Buffer))
        End While
    End Sub
#End Region
End Class


You can figure that if I define a buffer of 4000 bytes, I read just 4000 bytes of data sent by the device, but the device keep sending data all the time and I need to keep reading data all the time too, not just 4000 bytes... Is there a way to read data all the time and process this data at the very moment it is received?

Thanks in advance.
Eric Márquez

AnswerRe: TCP Socket client communication without using a buffer Pin
Eddy Vluggen25-Oct-11 7:19
professionalEddy Vluggen25-Oct-11 7:19 
QuestionSyntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Amanjot23-Oct-11 15:17
Amanjot23-Oct-11 15:17 
AnswerRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev23-Oct-11 15:34
protectorAspDotNetDev23-Oct-11 15:34 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Amanjot23-Oct-11 16:03
Amanjot23-Oct-11 16:03 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev23-Oct-11 16:10
protectorAspDotNetDev23-Oct-11 16:10 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Amanjot25-Oct-11 16:45
Amanjot25-Oct-11 16:45 
AnswerRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev25-Oct-11 17:02
protectorAspDotNetDev25-Oct-11 17:02 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Amanjot30-Oct-11 6:05
Amanjot30-Oct-11 6:05 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev30-Oct-11 8:43
protectorAspDotNetDev30-Oct-11 8:43 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Amanjot31-Oct-11 9:53
Amanjot31-Oct-11 9:53 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev31-Oct-11 19:21
protectorAspDotNetDev31-Oct-11 19:21 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Hypermommy7-Nov-11 9:28
Hypermommy7-Nov-11 9:28 
AnswerRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev7-Nov-11 9:38
protectorAspDotNetDev7-Nov-11 9:38 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Hypermommy7-Nov-11 10:01
Hypermommy7-Nov-11 10:01 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Hypermommy7-Nov-11 10:16
Hypermommy7-Nov-11 10:16 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
AspDotNetDev7-Nov-11 10:43
protectorAspDotNetDev7-Nov-11 10:43 
GeneralRe: Syntax Error (missing Operator) in query expression '07/08/2011 12:00:00 PM'. Pin
Hypermommy8-Nov-11 3:44
Hypermommy8-Nov-11 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.