Data Logger

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

TCP Transfer issues 3
Testing client server application from single computer 3
NNTP Client 4
sending file 1
How to debug this? 10
TCP/IP 3
send file 1
a simple client example 3

Top