Data Logger

  • Thread starter Thread starter Shawnmb
  • Start date Start date
S

Shawnmb

Hi everybody,
I'm still relatively new to VB.NET, so please excuse me in my
noobishness :)
So far I have started working off of a client/server socket tutorial
(http://www.eggheadcafe.com/articles/20020323.asp), essentially I'm
writing a console application that listens on a specific port and
outputs all data to the console, later on I would like to add replies
to specific incoming data. I also am not sure what encoding the
incoming data will be, I'm not sure how to have VB figure that out.

Here is the code so far (nothing special at all):

Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports System.Random

Module Module1
Sub Main()
Console.WriteLine("Loading...")
Const portNum As Integer = 2107
Console.WriteLine("Port " & portNum & " bound.")
Dim Listener As New System.Net.Sockets.TcpListener(portNum)
Console.WriteLine("Waiting for a connection...")
Listener.Start()

Try
Dim tcpClient As TcpClient = Listener.AcceptTcpClient()
Console.WriteLine("Connection established.")
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Recieved: " + clientdata))

'We aren't sending a response yet ^^
'Dim responseString As String = "Connected."
'Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(responseString)
'networkStream.Write(sendBytes, 0, sendBytes.Length)
If clientdata = "exit" Then
tcpClient.Close()
Listener.Stop()
End
End If

Catch e As Exception
MsgBox("Boom")
Console.WriteLine(e.ToString())
Console.ReadLine()
End Try

End Sub

End Module

Does anyone have any suggestions or tips for me? ^_^
Thanks,
Shawn
 
Back
Top