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:
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:
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()
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