Click here to Skip to main content
15,881,172 members
Articles / Programming Languages / Visual Basic
Article

TCP/IP with VB.NET

Rate me:
Please Sign up or sign in to vote.
3.65/5 (30 votes)
12 Aug 20043 min read 316.9K   22.1K   69   31
TCP/IP with VB.NET.

Image 1

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.
    VB
    Dim Cli as New UNOLibs.Net.ClientClass
  • Use it to send a specified MESSAGE on specified IP and PORT.
    VB
    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.
    VB
    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.
    VB
    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.
    VB
    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.
    VB
    Scanner.StartScan
  • What to do when IPs are found?
    VB
    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


Written By
Web Developer
Italy Italy
...picture was not for codeproject hihihi.
well my usual way is to release only classes wich can be used by you very easily and quickly.

Comments and Discussions

 
QuestionMe.IncomingMessagesList.Items.Add(Args.senderIP + " --> " + Args.message) this line gives error Pin
Member 410891216-May-22 5:26
Member 410891216-May-22 5:26 
QuestionIPAddress not reached Pin
Member 410891216-May-22 4:02
Member 410891216-May-22 4:02 
QuestionNot Working if Network Service provider different Pin
sayalisansurve25-Jul-17 2:42
sayalisansurve25-Jul-17 2:42 
Questionhi Pin
taneka20-Feb-12 10:34
taneka20-Feb-12 10:34 
Questionsalam Pin
arastoooo6-Sep-11 9:48
arastoooo6-Sep-11 9:48 
QuestionHow To: Receive Data from the Client Class? Pin
antonio62228-Jan-11 8:00
antonio62228-Jan-11 8:00 
GeneralSpecial charcaters Pin
PenelopeGuido15-Aug-06 0:06
PenelopeGuido15-Aug-06 0:06 
GeneralEvent when connect to Port Pin
Vitoto20-Jun-05 10:01
Vitoto20-Jun-05 10:01 
GeneralRe: Event when connect to Port Pin
uno freeware22-Jun-05 4:39
uno freeware22-Jun-05 4:39 
GeneralRe: Event when connect to Port Pin
uno freeware22-Jun-05 4:44
uno freeware22-Jun-05 4:44 
GeneralRe: Event when connect to Port Pin
Anonymous22-Jun-05 5:16
Anonymous22-Jun-05 5:16 
GeneralRe: Event when connect to Port Pin
uno freeware22-Jun-05 6:15
uno freeware22-Jun-05 6:15 
GeneralRe: Event when connect to Port Pin
Vitoto22-Jun-05 15:11
Vitoto22-Jun-05 15:11 
GeneralRe: Event when connect to Port Pin
uno freeware23-Jun-05 6:26
uno freeware23-Jun-05 6:26 
GeneralRe: Event when connect to Port Pin
Vitoto23-Jun-05 7:14
Vitoto23-Jun-05 7:14 
GeneralSystem.NullReferenceException Error Pin
Curse4Life20-Jun-05 4:33
Curse4Life20-Jun-05 4:33 
GeneralRe: System.NullReferenceException Error Pin
uno freeware22-Jun-05 4:27
uno freeware22-Jun-05 4:27 
GeneralRe: System.NullReferenceException Error Pin
Curse4Life22-Jun-05 20:38
Curse4Life22-Jun-05 20:38 
GeneralRe: System.NullReferenceException Error Pin
uno freeware23-Jun-05 6:24
uno freeware23-Jun-05 6:24 
GeneralRe: System.NullReferenceException Error Pin
PenelopeGuido14-Aug-06 7:38
PenelopeGuido14-Aug-06 7:38 
GeneralRe: System.NullReferenceException Error Pin
uno freeware22-Jun-05 4:45
uno freeware22-Jun-05 4:45 
GeneralPEOPLE GOTO UNOLIBS V2 Pin
uno freeware15-Jun-05 17:37
uno freeware15-Jun-05 17:37 
Generalnnbn Pin
raj451115-Apr-05 3:57
sussraj451115-Apr-05 3:57 
GeneralRe: nnbn Pin
Uno.Freeware16-Apr-05 9:34
sussUno.Freeware16-Apr-05 9:34 
QuestionWhy this low rating? Pin
BlueFront27-Mar-05 21:02
BlueFront27-Mar-05 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.