Click here to Skip to main content
15,897,518 members

VB.NET console output issue

Sicppy asked:

Open original thread
I created a code that should scroll through an array of data streams and output the stream as soon as one of them gets input, but everytime it gets input it outputs like it should but with a following 20 blank lines, please help,

-Jordan

Contents of module1.vb:
VB
Module Module1
    Dim Socket As New Socket_Control.Server_Socket
    Dim inStream As New Threading.Thread(AddressOf Streaming)
    Dim Connected As Boolean = False

    Sub Main()
        msg("Max Client Slots:")
        Console.Write(" >> ")
        Dim max As String = Console.ReadLine()
        msg("Port: ")
        Console.Write(" >> ")
        Dim port As String = Console.ReadLine()
        Socket.MaxSlots = max
        Socket.Port = port
        Socket.Start()
        Connected = True
        msg("Now Monitoring Port: " & Socket.Port)
        inStream.Start()
        While True

        End While
    End Sub

    Private Sub Streaming()
        While True
            Dim Count As Integer = 0
            While Not Count = Socket.MaxSlots
                Dim Stream As String = Socket.Stream(Count)
                If Not Stream = "%False%" Then
                    msg("[CLIENT " & Count + 1 & "] " & Stream)
                End If
                Count += 1
            End While
        End While
    End Sub

    Private Sub msg(ByVal Message As String)
        Console.WriteLine(" >> " & Message)
    End Sub
End Module


Socket_Control.dll Server_Socket Class:
VB
Imports System.Windows.Forms
Imports System.Net.Sockets
Imports System.Text

Public Class Server_Socket
    Private boolConnected As Boolean = False
    Public Event ClientDisconnect()

    Public Property Port As Integer = 55344
    Public Property MaxSlots
    Public Event ConnectionEstablished()

    Public ReadOnly Property Connected
        Get
            Return boolConnected
        End Get
    End Property

    Private Socket As TcpListener
    Private Client(1) As TcpClient
    Private serverStream As NetworkStream
    Private Connection As New Threading.Thread(AddressOf AwaitConnection)

    Private sendData(10000) As Byte
    Private recieveData(10000) As Byte

    Private WithEvents Timer As New Timer

    Public Sub Start()
        Socket = New TcpListener(Port)
        ReDim Client(MaxSlots - 1)
        Socket.Start()
        Connection.Start()
        'Timer.Interval = 100
        'Timer.Enabled = True
    End Sub

    Private Sub AwaitConnection()
        Dim Count As Integer = 0
        While True
            If Socket.Pending() AndAlso Not Count = MaxSlots Then
                Client(Count) = Socket.AcceptTcpClient
                Count += 1
            End If
        End While
    End Sub

    Public ReadOnly Property Stream(ByVal ID As String)
        Get
            If Not Client(ID) Is Nothing Then
                serverStream = Client(ID).GetStream()
                If Client(ID).GetStream.DataAvailable Then
                    serverStream.Read(recieveData, 0, 10000)
                    Return Encoding.ASCII.GetString(recieveData)
                Else
                    Array.Clear(recieveData, 0, 10000)
                    Return "%False%"
                End If
            Else
                Return "%False%"
            End If
        End Get
    End Property

    Public Sub DataSend(ByVal data)
        Try
            sendData = Encoding.ASCII.GetBytes(data)
            serverStream.Write(sendData, 0, sendData.Length)
        Catch ex As Exception
            boolConnected = False
            RaiseEvent ClientDisconnect()
        End Try
    End Sub
End Class
Tags: Visual Basic, Sockets

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900