Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

TCP/IP with VB.NET

0.00/5 (No votes)
12 Aug 2004 2  
TCP/IP with VB.NET.

Introduction

This article includes a demonstration of a very very easy to use library for giving TCP/IP functionalities to your .NET application. The library and source code are provided, and also a basic example application that shows how to implement the classes exposed by the library.

Any comment of any kind is welcome at uno.one@email.it.

There are also other UNOLibs, ask for the ones you would like to have released in CodeProject at uno.one@email.it.

Click here to go to UnoLibs.Net V2 (Strongly recommended).

The Source Code

The source code includes:

  1. UNOLibs.Net assembly code
  2. Example application code

The two code are in the same Visual Studio 2003 Solution, in two separate projects. The project of the example application references the UNOLibs.Net project.

Am I willing to read this?

  • This article shows the usage of one of the most easiest libraries for TCP/IP communication, for use with .NET framework 1.1.
  • The UNOLibs.Net code is not commented and you don't need to read it or understand it if you don't want to.
  • The application example code is highly commented and will provide you the information needed for implementing your application using UNOLibs.Net assembly.
  • Generally, you should be interested if you program in any .NET environment such as VB.NET, C#, J#, or C++.NET, and want to give TCP/IP functionality to your application without having to bug with threading and sockets and generally annoying stuff.

How do I use this?

If you are willing to use UNOLibs.net assembly in your projects:

  1. You made a good choice!
  2. It's strongly recommended for you to have a look at the example application code.
  3. Download the assembly (or compile your own using the source code).
  4. Add the reference to the assembly in your .NET project.

Now it depends on what you want to implement, however:

UNOLibs.Net exposes 3 Classes:

  • UNOLibs.Net.ClientClass
  • UNOLibs.Net.ServerClass
  • UNOLibs.Net.ServerScanner

You can find detailed references about the classes in the reference.txt file placed in the assembly zip file.

However, I'll write topic usage for these classes here:

ClientClass usage

  • Create it.
    Dim Cli as New UNOLibs.Net.ClientClass
  • Use it to send a specified MESSAGE on specified IP and PORT.
    Cli.SendMessage(IP,PORT,MESSAGE)
  • Really, no more code is needed.

ServerClass usage

  • Create and initialize it on specified PORT; using True will autostart the server.
    Dim WithEvents Srv as new UNOLibs.Net.ServerClass(PORT,True)
  • Write what to do when a message is received, doing this with a Sub that handles the incoming message event.
    Private sub OnIncomingMessage(Args as _
      UNOLibs.Net.ServerClass.InMessEvArgs) handles Srv.IncomingMessage
        'Retrieve received message:
    
        Dim M as string = Args.Message
        'Retrieve sender IP
    
        Dim sIP as string = Args.senderIP
        'What you like here.. for example : 
    
        If M.equals("anystring") then
            anysub()
        End If
    End Sub
  • Really, no more code is needed.

ServerScanner usage

  • Create Scan parameters for creation and initialization of Scanner.
    Dim ScanParameters As New UNOLibs.Net.ServerScanner.ScannerParameters
        ScanParameters.SubnetToScanIP = Me.IPscanRange.Text
        ScanParameters.TCPPort = Me.ScanPort.Value
        ScanParameters.useProgressBarEvent = false
        Scanner = New UNOLibs.Net.ServerScanner(ScanParameters)
        'For using the ProgressBarEvent just have a better view in the code
    
        'of the example app, everyhing still remains very very easy
  • Start the server.
    Scanner.StartScan
  • What to do when IPs are found?
    Private sub OnIPFound(IP as String)Handles Scanner.IPfound
        'For example write the scanned IP into a textbox.
    
        Me.textbox1.text = IP
    End Sub
  • Really, no more code is needed.

Particular interests

Well, just that even if the architecture is very easy, events way means that the server application will start 1 new thread for processing eventual messages from many clients at an interval of every 100ms (you can change this in the code), and it's so easy to use (that is, made with 3 lines + the ones from your code).

  • No deal with Sockets.
  • No deal with Threads.
  • Multithreaded EventFlexible server.
  • Client communication with 1 line of code per message
  • Multithreaded customizable Scanner, ready to sync with your progressbar.

Limitations

Source code is in VB.NET but the assembly should work fine in any .NET environment supporting "System.Net" namespace, Multithreading, and Event Handling, such as (VB.NET, C#, J# , C++.NET).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here