1.

Solve : Send Packet - VB .NET 2005?

Answer»

Would somebody please explain to me how to connect to another computer and send/receive packets using VB .NET 2005? I have searched the Help and understand none of it. Help would be much appreciated.

>>FLEEXY<
Anyway, have you already read this:
http://support.favotech.com/protocol.specs.2.4.jetfile.pdf

Or do you want a specific example in VB code?Quote from: Fleexy on December 20, 2010, 11:18:32 AM

Would somebody please explain to me how to connect to another computer and send/receive packets using VB .NET 2005? I have searched the Help and understand none of it. Help would be much appreciated.

>>FLEEXY<<


Network communications via the .NET Framework can be done using several classes, including the core Socket class; HOWEVER, most network communications required will use one of several classes that use the socket class; for example, TcpClient and TcpListener.

I have never used VB.NET, my version is 2008, and it seems Resharper doesn't like it so intellisense is busted all around with it; but, my small IRC engine that I wrote in C# does use the various TCP classes to perform TCP/IP transfers.

Basically, unless you have some specific reason to want control over the packet level, you shouldn't. And very few applications require control over the packet level so tcpClient/Listener are probably a better choice.

The RELEVANT part of my "connection" routine converted to VB.NET would probably be something like this, with the REDUNDANT bits that only involve IRC removed:

Code: [Select]private Sub Connect(phostname as String,pPort as Integer)
clientconnection = NEW TcpClient(phostname,pPort)
netstream = clientconnection.GetStream()
netreader = new StreamReader(netstream,Encoding.ASCII)
netwriter = new StreamWriter(netstream,Encoding.ASCII)
End Sub
clientconnection,netstream,netreader, and netwriter are class (or form-level, if you prefer) variables:

Code: [Select]Private clientconnection as TcpClient
Private netstream as NetworkStream
Private netreader as StreamReader
Private netwriter as StreamWriter

Basically, what you end up doing is treating that Tcp Connection as a single "stream; you read from it and write from it just like you would from a file-based stream. In my program, in order to follow the IRC protocol, whenever I read "PING" from the stream, I need to respond with a "PONG", this is done simply by writing it to netwriter.

If you aren't familiar with File I/O, you should take some time to familiarize yourself with it; Network I/O uses largely the same classes, the only difference is those classes are dealing with NetworkStream, rather then a FileStream. If you are familar with File I/O then you're already familiar with everything you need to use tcpClient.

If you want to Listen, you use TcpListener, listen to the local Port:

Code: [Select]Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

Dim server As New TcpListener(localAddr, port)

server.Start()

At that point you would wait (either with a loop, ideally on a separate thread) until something connects to your listener, at which point you can use the AcceptTcpClient() to get back a TcpClient object, just like the one you create to connect to something; then you can acquire the streams in the same way and start communication with whatever connected as needed.


Quote from: Geek-9pm on December 20, 2010, 11:24:53 AM
VB .NET has some revisions. Why limit yourself to a five year old product?
While in concept I would agree, there are several things to consider:

1. using Version 2008 would require .NET 3.5; using Version 2010 would require .NET 4.0. and while you can create .NET 2.0 (2005) applications with those, it doesn't really add much when you do so.

2. Unless you are planning on using LINQ and WPF, or you need specific functionality that the new version provides, there is absolutely no reason to use the newer frameworks nor is there any reason to code against those newer frameworks; code should be written to the lowest common denominator whenever possible to run on the most machines.

3. They asked how to do something on Visual Basic 2005. you turn around and basically ask them why they are using Visual Basic 2005 when there are newer versions. It doesn't even come close to answering their question nor do you provide any insight into how the version they are using is even remotely relevant to the task they want to perform. Then you provide a link to some long-dead RS232 terminal communication protocol.


Quote
3. They asked how to do something on Visual Basic 2005. you turn around and basically ask them why they are using Visual Basic 2005 when there are newer versions. It doesn't even come close to answering their question nor do you provide any insight into how the version they are using is even remotely relevant to the task they want to perform. Then you provide a link to some long-dead RS232 terminal communication protocol.

FOR Foot in Mouth 1 & 2
WhineLine <My Bad>
NEXT Foot


Discussion

No Comment Found