473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Data Logger

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

Mar 19 '06 #1
1 2259
Hi,

Take a look at remoting. I think that might be a better choice
for passing data.
http://msdn.microsoft.com/library/de...ngoverview.asp

Ken
--------------------

"Shawnmb" wrote:
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

Mar 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Laszlo | last post by:
Hi I need a GL::Logger wich implements Class::Singleton to be a singleton and Log::Log4perl to can log amy message into a file. Here is the module source:...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
3
by: Phil Sherman | last post by:
What is the relationship between the snapshot elements: Log pages written Number write log IOs Number partial page log IOs There doesn't appear to be any information in my PDF System monitor...
4
by: garyjefferson123 | last post by:
Suppose I have some sort of context variable that I want to appear in log messages. E.g.: logger = logging.getLogger("somelogger") class SomeOp: def __init__(self, ctx): self.ctx = ctx def...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.