Thanks again. I am probably one of the sloppiest programmers around, but I have seen worse. And I'm still in a steep learning curve on this. I was using type object because the stream is made up of integers, doubles and strings. But you are right that I should format it all as string.
The data comes in over the Internet to this computer running the VB.NET program which is listening for anything on port 81. When the data arrives it's parsed and some calculations are made on it. I then need to send this data back over the net to the machine where it originated which is at hour hosting company. That's basically it. Since this is only a prototype I can post the code I'm working with.
This is the Tcp listener code.
Code:
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Public Class Form1
Dim Listener As New TcpListener(81)
Dim Client As New TcpClient
Dim Message As String = ""
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ListThread As New Thread(New ThreadStart(AddressOf Listening))
ListThread.Start()
End Sub
Private Sub Listening()
Listener.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Client = New TcpClient("192.168.0.2", 81)
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(ParseData(Message))
Writer.Flush()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Listener.Pending = True Then
Message = ""
Client = Listener.AcceptTcpClient()
Dim Reader As New StreamReader(Client.GetStream())
While Reader.Peek > -1
Message = Message + Convert.ToChar(Reader.Read()).ToString
End While
ReplyIt(Message)
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Listener.Stop()
End Sub
Sub ReplyIt(ByVal Message As Object)
Client = New TcpClient("192.168.0.1", 81)
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(ParseData(Message))
Writer.Flush()
End Sub
Function ParseData(ByVal vStream As Object)
Dim vWord(15) As Object
Dim count As Integer
vStream = Mid(vStream, InStr(vStream, "id="))
Dim words As Object() = vStream.Split("&")
Dim word As Object
'"C:\Temp\" & Mid(Mid(vStream, 4), 1, InStr(Mid(vStream, 4), "&") - 1) & ".txt"
For Each word In words
vWord(count) = Mid(word, InStr(word, "=") + 1)
count = count + 1
Next
Return vWord(0) & Chr(9) & vWord(1) & " x " & vWord(2)
End Function
End Class