Monday, December 31, 2007

How to: Use Named Pipes to Communicate Between Processes over a Network

How to: Use Named Pipes to Communicate Between Processes over a Network
Named pipes offer more functionality than anonymous pipes. This functionality includes full duplex communication over a network and multiple server instances; message-based communication; and client impersonation, which enables connecting processes to use their own set of permissions on remote servers.

Imports System
Imports System.IO
Imports System.IO.Pipes
Imports System.Threading

Class PipeServer
Shared numThreads As Integer = 4

Shared Sub Main()
Dim i As Integer
For i = 1 To numThreads
Dim newThread As New Thread(New ThreadStart(AddressOf ServerThread))
newThread.Start()
Next
End Sub

Private Shared Sub ServerThread()
Dim pipeServer As New NamedPipeServerStream("testpipe", _
PipeDirection.InOut, numThreads)

Console.WriteLine("NamedPipeServerStream thread created.")

' Wait for a client to connect
pipeServer.WaitForConnection()

Console.WriteLine("Client connected.")
Try
' Read the request from the client. Once the client has
' written to the pipe, its security token will be available.
Dim sr As New StreamReader(pipeServer)
Dim sw As New StreamWriter(pipeServer)
sw.AutoFlush = True

' Verify our identity to the connected client using a
' string that the client anticipates.
sw.WriteLine("I am the true server!")

' Obtain the filename from the connected client.
Dim filename As String = sr.ReadLine()

' Read in the contents of the file while impersonating
' the client.
Dim fileReader As New ReadFileToStream(pipeServer, filename)

' Display the name of the clientr we are impersonating.
Console.WriteLine("Reading file: {0} as user {1}.", _
filename, pipeServer.GetImpersonationUserName())

pipeServer.RunAsClient(AddressOf fileReader.Start)

pipeServer.Disconnect()

sr.Close()
sw.Close()
Catch ex As Exception
Console.WriteLine("ERROR: {0}", ex.Message)
End Try
pipeServer.Close()
End Sub
End Class

Public Class ReadFileToStream
Private m_filename As String
Private m_stream As Stream

Public Sub New(ByVal stream1 As Stream, ByVal filename As String)
m_filename = filename
m_stream = stream1
End Sub

Public Sub Start()
Using sw As New StreamWriter(m_stream)
Dim contents As String = File.ReadAllText(m_filename)
sw.WriteLine(contents)
sw.Flush()
End Using
End Sub
End Class

Imports System
Imports System.IO
Imports System.IO.Pipes
Imports System.Security.Principal

Class PipeClient

Shared Sub Main(ByVal args As String())

Try
Dim pipeClient As New NamedPipeClientStream("localhost", _
"testpipe", PipeDirection.InOut, PipeOptions.None, _
TokenImpersonationLevel.Impersonation)
Dim sw As New StreamWriter(pipeClient)
Dim sr As New StreamReader(pipeClient)
sw.AutoFlush = True

pipeClient.Connect()

' Verify that this is the "true server"
'Dim serverID As String = sr.ReadLine()
If 1 = 1 Then

' The client security token is sent with the first write
sw.WriteLine("c:\textfile.txt")

' Print the file to the screen.
Dim buffer(32) As Char
Dim n As Integer

n = sr.Read(buffer, 0, buffer.Length)
While Not n = 0
Console.Write(buffer, 0, n)
End While
Else
Console.WriteLine("Server could not be verified.")
End If
sw.Close()
sr.Close()
pipeClient.Close()
Catch ex As Exception
Console.WriteLine("ERROR: {0}", ex.Message)
End Try
End Sub
End Class



Robust Programming
The client and server processes in this example are intended to run on the same computer, so the server name provided to the NamedPipeClientStream object is "localhost". If the client and server processes were on separate computers, "localhost" would be replaced with the network name of the computer that runs the server process.

Asynchronous File I/O in VB.Net

Asynchronous File I/O in VB.Net

Built-In Asynchronous I/O Support in ASP.NET

Built-In Asynchronous I/O Support in ASP.NET

Built-In Asynchronous I/O Support in ASP.NET


Common Scenarios / Built-In Solutions


As we all know, I/O operations is one of the most time
consuming operations. In the same time, IO is one of the most needed operations
almost in all applications. To make our applications faster and having more
responsive user interface, we need to perform those I/O operations
asynchronously.


So, this is a common scenario, frequently needed and
frequently used.


To make your life easier, many .NET framework classes that
provide I/O services come with built-in methods that support and implement the
asynchronous execution pattern. This saves you from creating and instantiating
delegates to run the I/O operations asynchronously.


In this tutorial we will present the most common I/O
scenarios, with their built-in asynchronous execution patterns.


Asynchronous File Access


Accessing a file in your file system, opening it, reading
from it, or writing to it, is one of the most time consuming operations, and in
the same time is a frequently used operation.


The situation gets worse as the size of your file increase
or the number of files to be accessed increase. As usual, to solve this problem
we need to use asynchronous execution pattern. Fortunately, this technique is
supported in the .NET framework stream classes.


Accessing files is performed by using the "Stream" class.
This class is inherited by all other classes that deal with data streams. This
object supports the "BeginRead", "BeinWrite", "EndRead", and "EndWrite" methods,
that perform the reading or writing operations asynchronously.


One of those classes that inherits the "Stream"
class is the "FileStream" class. This class supports the four asynchronous
methods mentioned above. We will test this class's asynchronous execution
pattern through the following example:


Open Visual Studio 2005. Choose "New / Web Site", and give
it a name and location. Now, in the "Default.aspx" design view draw a label
control from the Tool Box.


Double click in the page body to activate the "Page_Load"
event handler. In the "Default.aspx.vb" type the following code.


    1 Imports System.io
    2 Partial Class _Default
    3     Inherits System.Web.UI.Page
    4 
    5     Protected Sub Page_Load(ByVal sender As Object, _
    6      ByVal e As System.EventArgs) Handles Me.Load
    7         ProcessFiles()
    8     End Sub
 
    9     Public Sub ProcessFiles()
   10 
   11 
   12         Dim AR As IAsyncResult
   13         Dim FS As New FileStream("c:\File.txt", _
   14          FileMode.Open, FileAccess.Read)
 
   15         Dim Arr(FS.Length) As Byte
   16         AR = FS.BeginRead(Arr, 0, FS.Length, _
  AddressOf EndRead_Callback, Nothing)
   17 
   18         Dim i As Integer
   19         For i = 0 To 10
   20             MsgBox(i.ToString)
   21         Next
   22 
   23     End Sub
 
   24     Public Sub EndRead_Callback(ByVal R As IAsyncResult)
   25 
   26         If R.IsCompleted Then
   27             MsgBox("Completed")
   28         End If
   29 
   30     End Sub
   31 End Class

As you can see, we first import the "System.IO" namespace.
In the "Page_Load" event handler we make a call to a subroutine called
"ProcessFiles" from which the asynchronous execution pattern will be carried
out. In the "ProcessFiles" subroutine we do the following: We declare an object
"AR" of type "IAsyncResult" to hold the state of the asynchronous operation. We
then instantiate a file stream object passing to it a file path name, the file
mode, and the access mode. Then we declare an array of type "Byte" with a length
equal to the length of our file. After that we call the "BeginRead" method of
the instantiate file stream object, passing to it the array of bytes we
just created as a buffer to read data into, the index of the array at which we
begin reading, the maximum number of bytes to read, and the callback method
which will be called automatically after the asynchronous operation completes,
and an object that can be used to put whatever data you want for this operation.
The output of the "BeginRead" method is assigned to the "AR" object.


In the lines from 18 to 21, we created a loop that displays
a message box just to test the user interface responsiveness while the
asynchronous operation is being carried out. Starting at line 24 we create the
callback method, which tests the completion of the operation and displays a
message box according to that.


Note: To get a satisfying feeling of the asynchronous
reading operation, you will need to choose a file with a length not less than
100 MB. Now run the application and observe the following results: First, the
application will display a sequence of message boxes displaying numbers from 0
to 10. Then the label text will be displayed, after a while the message box that
indicates operation completeness should popped up. This sequence may vary
depending on the length of your file.


As a result, the user interface responsiveness is excellent
and the reading asynchronous operation is completed successfully.


To download the complete example, click here.


Asynchronous Remoting


Remoting is a very useful technique you can use to build a
widely distributed applications easily. With remoting you can make your
application communicate with other processes on the same computer, processor, or
on any other computer that is reachable over the network. You can also use it to
perform communication with other application domains within the same
process.


Asynchronous programming technique in a remoting scenario
that is identical to the asynchronous programming technique used within one
application domain or context.


As with a single application domain, the asynchronous
operation over remoting have the following steps:




  • Create an object with a method that will execute the remote calling
    procedure, and instantiate it.
  • Define a delegate of type "AsyncDelegate" to the above method.
  • Create a callback method.
  • Define a delegate of type "AsyncCallback" delegate to the above created
    callback method.
  • Call the "BeginInvoke" method of the first defined delegate to run the
    method that perform remote calling in asynchronous execution pattern.
  • Do some other different work until your callback method is called.



        Dim RemoteDelegate As New RemoteAsyncDelegate _
         (AddressOf RObj.RemoteMethod)
        Dim RemoteCallbackFun As New AsyncCallback _
         (AddressOf CallbackMethod)
        Dim RAR As IAsyncResult = RemoteDelegate.BeginInvoke _
         (RemoteCallbackFun, Nothing)
 
        ' Do some other task

As you can observe this is exactly the same procedure we
used when we wanted to call any other local method asynchronously.


XML Web Services


In the recent years, the need for interoperability across
platforms to connect people, information, and processes has increased. This of
course has affected the way software is being developed. Web services comes to
this world to satisfy this need. Web services technology is concerned with
producing interoperability across platforms. This means that two different
platforms can communicate together, each installing an application written by
different programming languages and techniques, but all must use the same
protocol to be able to communicate together. This communication is done by using
the XML universal language for representing transmitted structured
messages and data that is independent of the underlying programming
languages, software platforms, and hardware. This is what we call XML web
services ...


What concerns us here, is the communication with XML web
services asynchronously. This follows the asynchronous design pattern used in
the rest of .NET framework.


It is nice to note that: To communicate with an XML web
service in asynchronous way, then this does not require this service to be
written especially to handle asynchronous calls. The methods that handle
asynchronous execution pattern is automatically created by the proxy class you
created for your client. For each synchronous method you create, the proxy class
automatically creates two methods which are: "Begin...", and "End...", to give
you the ability to call the method you created asynchronously when you need
to.


Asynchronous Network Communications


Nowadays most applications need the ability to communicate
with the network or as we call it: the Internet. Your application can
communicate with the network (even it is not an ASP. NET application) using many
ways. Some of them are through the "WebRequest" class by which you can request a
resource given its URL, or through the "Socket" class which provides a rich set
of methods and properties for network communication. These two classes are the
most popular classes used in network communications.


As the rest of all .NET framework asynchronous programming
model, the "WebRequest" and the "Socket" classes both follow this model. Means
that each class have its asynchronous methods. As usual, asynchronous methods
always start with the words "Begin....", and "End....".


As an example, to make an asynchronous requests using the
"WebRequest" class, instead of using the "GetResponse" method use
"BeginGetResponse" and "EndGetResponse" to do the same task asynchronously. This
is the only difference between calling the method synchronously or
asynchronously, the rest is alike. Of course, you can use callback methods, and
all blocking or waiting techniques you usually use with the asynchronous
execution pattern.


Both asynchronous client sockets, and asynchronous server
sockets follow the .NET framework asynchronous programming model.


For example, with the asynchronous client socket: Instead
of using the synchronous "Receive" method, use the asynchronous "BeginReceive",
and "EndReceive" methods.


With asynchronous server socket, instead of using the
synchronous "Accept" method, use its asynchronous equivalent "BeginAccept", and
"EndAccept" methods.





Related articles:

1. Multithreading in ASP.NET
2. Manual Threading in ASP.NET 2.0
3. Use Asynchronous Execution Pattern in ASP.NET
4. .NET Application Domains
5. Interoperating with Unmanaged Code - PInvoke

Asynchronous File I/O

XAML Sparkline example

XAML Sparkline example

ewbi.develops: Sparklines

ewbi.develops: Sparklines
source

Simple Sparklines Wordpress plugin, version 0.2

Simple Sparklines Wordpress plugin, version 0.2

BonaVista Systems – Sparklines, Dashboards, Charting for Excel and Microsoft Business Intelligence

BonaVista Systems – Sparklines, Dashboards, Charting for Excel and Microsoft Business Intelligence

TiddlyWiki - Sparklines

TiddlyWiki - a reusable non-linear personal web notebook


this shows

How to inline your sparklines/images in PHP with data: URIs

How to inline your sparklines/images in PHP with data: URIs


Regular:sparklinedata: URIsparkline

Sparkline PHP Graphing Library

Sparkline PHP Graphing Library

Sparkline PHP Graphing Library

Sparkline PHP Graphing Library

Sparkline PHP Library

sparkline » Examples

Sparklines in Microsoft Office documents
BonaVista MicoCharts enhances your Excel chart library with columns , sparklines , win/lose , bar , pie and bullet graphs . It is perfectly suited for management dashboards and makes Excel a first choice dashboard tool.
Bissantz SparkMakerA free add-in which allows you to easily create and insert sparklines into Word, Excel and PowerPoint documents.
SparkCells Add-in for Microsoft Excel Free for personal use. Uses the Bissantz SparkFonts font set which must be downloaded and installed separately - (website not reachable)
sparklines.doc, a GPL'd Microsoft Word document (no jokes about oxymorons!) with macros that generate, as drawings within the document, line and bar chart sparklines.
Excel Idées proposes a FREE Microsoft Excel .xla file including UDF (user defined functions) for sparklines generation (bullet graphs, lines and bars)
Fernando Cinquegrani's sparkline spreadsheet was posted by Jon Peltier on Juice Analytics micro chart blog.

Sparklines on the Web
Facebook uses sparkline images to visually represent privacy settings.
Finianz uses sparkline to display stock charts
Google Analytics uses sparklines to show stats about website visits
Kwondoo uses sparklines for authors to include statistical information in their texts

.NET Framework Developer's Guide: Asynchronous File I/O

.NET Framework Developer's Guide: Asynchronous File I/O




Imports System
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Runtime.Remoting.Messaging
Imports System.Security.Permissions



Module BulkImageProcAsync
Dim ImageBaseName As String = "tmpImage-"
Dim numImages As Integer = 200
Dim numPixels As Integer = 512 * 512

' ProcessImage has a simple O(N) loop, and you can vary the number
' of times you repeat that loop to make the application more CPU-
' bound or more IO-bound.
Dim processImageRepeats As Integer = 20

' Threads must decrement NumImagesToFinish, and protect
' their access to it through a mutex.
Dim NumImagesToFinish As Integer = numImages
Dim NumImagesMutex(-1) As [Object]
' WaitObject is signalled when all image processing is done.
Dim WaitObject(-1) As [Object]

Structure ImageStateObject
Public pixels() As Byte
Public imageNum As Integer
Public fs As FileStream
End Structure


_
Sub MakeImageFiles()
Dim sides As Integer = Fix(Math.Sqrt(numPixels))
Console.Write("Making {0} {1}x{1} images... ", numImages, sides)
Dim pixels(numPixels) As Byte
Dim i As Integer
For i = 0 To numPixels
pixels(i) = 255
Next i
Dim fs As FileStream
For i = 0 To numImages
fs = New FileStream(ImageBaseName + i.ToString() + ".tmp", FileMode.Create, FileAccess.Write, FileShare.None, 8192, False)
fs.Write(pixels, 0, pixels.Length)
FlushFileBuffers(fs.SafeFileHandle.DangerousGetHandle())
fs.Close()
Next i
fs = Nothing
Console.WriteLine("Done.")

End Sub


Sub ReadInImageCallback(ByVal asyncResult As IAsyncResult)
Dim state As ImageStateObject = CType(asyncResult.AsyncState, ImageStateObject)
Dim stream As Stream = state.fs
Dim bytesRead As Integer = stream.EndRead(asyncResult)
If bytesRead <> numPixels Then
Throw New Exception(String.Format("In ReadInImageCallback, got the wrong number of " + "bytes from the image: {0}.", bytesRead))
End If
ProcessImage(state.pixels, state.imageNum)
stream.Close()

' Now write out the image.
' Using asynchronous I/O here appears not to be best practice.
' It ends up swamping the threadpool, because the threadpool
' threads are blocked on I/O requests that were just queued to
' the threadpool.
Dim fs As New FileStream(ImageBaseName + state.imageNum.ToString() + ".done", FileMode.Create, FileAccess.Write, FileShare.None, 4096, False)
fs.Write(state.pixels, 0, numPixels)
fs.Close()

' This application model uses too much memory.
' Releasing memory as soon as possible is a good idea,
' especially global state.
state.pixels = Nothing
fs = Nothing
' Record that an image is finished now.
SyncLock NumImagesMutex
NumImagesToFinish -= 1
If NumImagesToFinish = 0 Then
Monitor.Enter(WaitObject)
Monitor.Pulse(WaitObject)
Monitor.Exit(WaitObject)
End If
End SyncLock

End Sub


Sub ProcessImage(ByVal pixels() As Byte, ByVal imageNum As Integer)
Console.WriteLine("ProcessImage {0}", imageNum)
Dim y As Integer
' Perform some CPU-intensive operation on the image.
Dim x As Integer
For x = 0 To processImageRepeats
For y = 0 To numPixels
pixels(y) = 1
Next y
Next x
Console.WriteLine("ProcessImage {0} done.", imageNum)

End Sub


Sub ProcessImagesInBulk()
Console.WriteLine("Processing images... ")
Dim t0 As Long = Environment.TickCount
NumImagesToFinish = numImages
Dim readImageCallback As New AsyncCallback(AddressOf ReadInImageCallback)
Dim i As Integer
For i = 0 To numImages
Dim state As New ImageStateObject()
state.pixels = New Byte(numPixels) {}
state.imageNum = i
' Very large items are read only once, so you can make the
' buffer on the FileStream very small to save memory.
Dim fs As New FileStream(ImageBaseName + i.ToString() + ".tmp", FileMode.Open, FileAccess.Read, FileShare.Read, 1, True)
state.fs = fs
fs.BeginRead(state.pixels, 0, numPixels, readImageCallback, state)
Next i

' Determine whether all images are done being processed.
' If not, block until all are finished.
Dim mustBlock As Boolean = False
SyncLock NumImagesMutex
If NumImagesToFinish > 0 Then
mustBlock = True
End If
End SyncLock
If mustBlock Then
Console.WriteLine("All worker threads are queued. " + " Blocking until they complete. numLeft: {0}", NumImagesToFinish)
Monitor.Enter(WaitObject)
Monitor.Wait(WaitObject)
Monitor.Exit(WaitObject)
End If
Dim t1 As Long = Environment.TickCount
Console.WriteLine("Total time processing images: {0}ms", t1 - t0)

End Sub


Sub Cleanup()
Dim i As Integer
For i = 0 To numImages
File.Delete(ImageBaseName + i.ToString + ".tmp")
File.Delete(ImageBaseName + i.ToString + ".done")
Next i

End Sub


Sub TryToClearDiskCache()
' Try to force all pending writes to disk, and clear the
' disk cache of any data.
Dim bytes(100 * (1 << i =" 0" bytes =" Nothing" length =" 1" processimagerepeats =" Int32.Parse(args(0))"> _
Sub FlushFileBuffers(ByVal handle As IntPtr)
End Sub
End Module



Here is a synchronous example of the same idea.
Imports System
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Runtime.Remoting.Messaging
Imports System.Security.Permissions



Module BulkImageProcSync
Dim ImageBaseName As String = "tmpImage-"
Dim numImages As Integer = 200
Dim numPixels As Integer = 512 * 512

' ProcessImage has a simple O(N) loop, and you can vary the number
' of times you repeat that loop to make the application more CPU-
' bound or more IO-bound.
Dim processImageRepeats As Integer = 20

_
Sub MakeImageFiles()
Dim sides As Integer = Fix(Math.Sqrt(numPixels))
Console.Write("Making {0} {1}x{1} images... ", numImages, sides)
Dim pixels(numPixels) As Byte
Dim i As Integer
For i = 0 To numPixels
pixels(i) = 255
Next i
Dim fs As FileStream
For i = 0 To numImages
fs = New FileStream(ImageBaseName + i.ToString + ".tmp", FileMode.Create, FileAccess.Write, FileShare.None, 8192, False)
fs.Write(pixels, 0, pixels.Length)
FlushFileBuffers(fs.SafeFileHandle.DangerousGetHandle())
fs.Close()
Next i
fs = Nothing
Console.WriteLine("Done.")

End Sub


Sub ProcessImage(ByVal pixels() As Byte, ByVal imageNum As Integer)
Console.WriteLine("ProcessImage {0}", imageNum)
Dim y As Integer
' Perform some CPU-intensive operation on the image.
Dim x As Integer
For x = 0 To processImageRepeats
For y = 0 To numPixels
pixels(y) = 1
Next y
Next x
Console.WriteLine("ProcessImage {0} done.", imageNum)

End Sub


Sub ProcessImagesInBulk()
Console.WriteLine("Processing images... ")
Dim t0 As Long = Environment.TickCount
Dim pixels(numPixels) As Byte
Dim input As FileStream
Dim output As FileStream
Dim i As Integer
For i = 0 To numImages
input = New FileStream(ImageBaseName + i.ToString + ".tmp", FileMode.Open, FileAccess.Read, FileShare.Read, 4196, False)
input.Read(pixels, 0, numPixels)
input.Close()
ProcessImage(pixels, i)
output = New FileStream(ImageBaseName + i.ToString + ".done", FileMode.Create, FileAccess.Write, FileShare.None, 4196, False)
output.Write(pixels, 0, numPixels)
output.Close()
Next i
input = Nothing
output = Nothing
Dim t1 As Long = Environment.TickCount
Console.WriteLine("Total time processing images: {0}ms", t1 - t0)

End Sub


Sub Cleanup()
Dim i As Integer
For i = 0 To numImages
File.Delete(ImageBaseName + i.ToString + ".tmp")
File.Delete(ImageBaseName + i.ToString + ".done")
Next i

End Sub


Sub TryToClearDiskCache()
Dim bytes(100 * (1 << i =" 0" bytes =" Nothing" length =" 1" processimagerepeats =" Int32.Parse(args(0))"> _
Sub FlushFileBuffers(ByVal handle As IntPtr)
End Sub
End Module

See Also:
Reference: Stream Stream.Read Stream.Write Stream.BeginRead Stream.BeginWrite Stream.EndRead Stream.EndWrite IAsyncResult Mutex
Other Resources: File and Stream I/O

File Caching (Windows)

File Caching (Windows)
By default, Windows caches file data that is read from disks and written to disks. This implies that read operations read file data from an area in system memory known as the system file cache, rather than from the physical disk. Correspondingly, write operations write file data to the system file cache rather than to the disk, and this type of cache is referred to as a write-back cache. Caching is managed per file object.
Caching occurs under the direction of the cache manager, which operates continuously while Windows is running. File data in the system file cache is written to the disk at intervals determined by the operating system, and the memory previously used by that file data is freed—this is referred to as flushing the cache. The policy of delaying the writing of the data to the file and holding it in the cache until the cache is flushed is called lazy writing, and it is triggered by the cache manager at a determinate time interval. The time at which a block of file data is flushed is partially based on the amount of time it has been stored in the cache and the amount of time since the data was last accessed in a read operation. This ensures that file data that is frequently read will stay accessible in the system file cache for the maximum amount of time.
This file data caching process is illustrated in the following figure.

Visual Basic: Performance Counters Sample

Performance Counters Sample
This sample shows how to read from and write to performance counters. These counters can be used to track the performance of the operating system and .NET Framework applications. Both system and custom counters are used.

Getting Started with My.Blogs | Visual Studio 2005 Technical Articles

Getting Started with My.Blogs
Summary: My.Blogs is a collection of sample code that will show you how you can easily provide programmatic access to weblogs in the applications you build. Full source code is provided along with Windows Forms, ASP.NET 2.0, and a Visual Studio 2005 Tools for Office Outlook Add-In. (15 printed pages)

Visual Basic Fusion: Best Practices to Use Visual Basic 6 and Visual Basic .NET Together

Visual Basic Fusion: Best Practices to Use Visual Basic 6 and Visual Basic .NET Together
Summary: A Microsoft Visual Basic 6 application can access .NET class libraries, but to do so, it must go through an interoperability layer, known as a client callable wrapper. This wraps the desired .NET class, and exposes it so that it appears as a traditional COM object, which can be used from any environment that can consume COM objects. Learn how to create these wrappers. (18 printed pages)
Download the Visual Basic Fusion—Best Practices.msi code sample for this article.

Using Threading to Build a Responsive Application with Visual Studio 2005

Using Threading to Build a Responsive Application with Visual Studio 2005

Extending Visual Basic 6 ActiveX EXEs With Visual Basic 2005 and the Interop Forms Toolkit

Extending Visual Basic 6 ActiveX EXEs With Visual Basic 2005 and the Interop Forms Toolkit

Sharing ADO Recordsets Between Visual Basic 6 and Visual Basic 2005

Sharing ADO Recordsets Between Visual Basic 6 and Visual Basic 2005

Visual Basic 6 Asynchronous File IO Using the .NET Framework

Visual Basic 6 Asynchronous File IO Using the .NET Framework
There are many applications that need to monitor directories and process incoming files. Files could appear as data exported from a legacy system, as FTP or HTTP uploads, or a variety of other sources. I set out to build an application in Visual Basic 6 that would process incoming files. The Visual Basic 6 application needed to satisfy the following requirements:
A directory monitored on a background thread: The application needed to remain responsive and unblocked while waiting for files to appear.
File contents loaded on a background thread so that the application would not be blocked while large files were being loaded.
Some processing of the file contents.

Visual Basic 6 Asynchronous File IO Using the .NET Framework

Visual Basic 6 Asynchronous File IO Using the .NET Framework


Option Explicit

Dim WithEvents dirWatcher As DropDirMonitor.DirWatcher

Private Sub Form_Load()
Randomize

txtDropDir.Text = App.Path & "\Drop"
Set dirWatcher = New DropDirMonitor.dirWatcher
End Sub

Private Sub cmdStart_Click()
dirWatcher.Init txtDropDir.Text
End Sub

Private Sub cmdGenDataFile_Click()
Dim i As Integer

Dim fileName As String
fileName = txtDropDir.Text & "\" & Rand(1, 100000) & ".dat"

Open fileName For Output As #1

Print #1, "ProductID,Quantity,Price"

For i = 1 To Rand(5000, 30000)
Print #1, Rand(1, 100) & "," & Rand(1, 20) & "," & Rand(1, 50)
Next

Close #1
End Sub


Private Sub dirWatcher_ProcessingFile(ByVal fileName As String)
fileName = Right(fileName, Len(fileName) - InStrRev(fileName, "\"))
Text1.Text = Text1.Text & "Processing:" & fileName
DoEvents
End Sub

Private Sub dirWatcher_FileContentsAvailable(ByVal contents As String)
Dim lines() As String
lines = Split(contents, vbCrLf)

Dim total As Double
Dim line As Variant
For Each line In lines
Dim items() As String
items = Split(line, ",")
If UBound(items) > -1 Then
If IsNumeric(items(1)) Then
total = total + (CDbl(items(1)) * CDbl(items(2)))
End If
End If
Next

Text1.Text = Text1.Text & ", Total = " & FormatCurrency(total) &
vbCrLf
End Sub

Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function





_
Public Class DirWatcher
Inherits Control

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "db5b9156-4aa7-4a5d-a32d
-ceb6af2dc3e2"
Public Const InterfaceId As String = "2c22921f-2357-4215-9759
-0ba865a65d7a"
Public Const EventsId As String = "1c1e49dc-d641-41b3-9394
-b003de631c4d"
#End Region

Private WithEvents mFileSystemWatcher As New FileSystemWatcher

Private mDirectoryToWatch As String

Private filesToProcess As New List(Of String)

Public Sub New()
MyBase.New()
Me.CreateHandle()
End Sub

Public Sub Init(ByVal directoryToWatch As String)
mDirectoryToWatch = directoryToWatch
mFileSystemWatcher.Path = mDirectoryToWatch
mFileSystemWatcher.EnableRaisingEvents = True

For Each file As String In Directory.GetFiles(directoryToWatch)
filesToProcess.Add(file)
Next

ProcessNextFile()
End Sub

Private Sub mFileSystemWatcher_Created(ByVal sender As Object, _
ByVal e As System.IO.FileSystemEventArgs) _
Handles mFileSystemWatcher.Created

If Me.InvokeRequired Then
If e.ChangeType <> WatcherChangeTypes.Created Then Return

Me.Invoke(New EventHandler(Of FileSystemEventArgs) _
(AddressOf mFileSystemWatcher_Created), sender, e)
Else
filesToProcess.Add(e.FullPath)
ProcessNextFile()
End If
End Sub




Private Sub ProcessNextFile()
If filesToProcess.Count = 0 Then Return
If Me.Cancel = True Then Return

If Not mBackgroundWorker.IsBusy Then
Dim fileToProcess As String = filesToProcess(0)
filesToProcess.RemoveAt(0)
If File.Exists(fileToProcess) Then
mBackgroundWorker.RunWorkerAsync(fileToProcess)
End If
End If
End Sub

Private Sub mBackgroundWorker_DoWork(ByVal sender As Object, _
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles mBackgroundWorker.DoWork
Using sr As New StreamReader(File.Open( _
e.Argument, FileMode.Open, _
FileAccess.Read, FileShare.None))

mBackgroundWorker.ReportProgress(0, e.Argument)
e.Result = sr.ReadToEnd()
End Using
File.Delete(e.Argument)
End Sub

Private Sub mBackgroundWorker_RunWorkerCompleted( _
ByVal sender As Object, _
ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _
Handles mBackgroundWorker.RunWorkerCompleted

If e.Result IsNot Nothing Then
RaiseEvent FileContentsAvailable(e.Result)
End If

ProcessNextFile()
End Sub


ASProxy: Surf in the web invisibly using ASP.NET power

ASProxy: Surf in the web invisibly using ASP.NET power
With this tool which is written in ASP.NET 2 you can easily pass the filter and see the your desired web pages or you can even download files.

Current version: 4.0
SourceForge summary page
Download ASProxy version 4.0 source - 327 KB
Download ASProxyServer beta version 3.8.1 Installer- 1.3 MB
Download more languages
Download various interfaces

GParted - Gnome Partition Editor

GParted - Gnome Partition Editor

GParted is the Gnome Partition Editor application. Before attempting to use it, here is some basic background information.A hard disk is usually subdivided into one or more partitions. These partitions are normally not re-sizable (making one larger and the adjacent one smaller) The purpose of GParted is to allow the individual to take a hard disk and change the partition organization therein, while preserving the partition contents.GParted is an industrial-strength package for creating, destroying, resizing, moving, checking and copying partitions, and the filesystems on them. This is useful for creating space for new operating systems, reorganizing disk usage, copying data residing on hard disks and mirroring one partition with another (disk imaging).GParted uses GNU libparted to detect and manipulate devices and partitiontables.Several (optional) "file system" tools provide support for file systems not included in libparted.These optional packages will be detected at runtime and do not require a rebuild of GParted.GParted is written in C++ and uses gtkmm for its Graphical User Interface (GUI). The general approach is to keep the Graphical User Interface as simple as possible. Every attempt was made to conform to the GNOME Human Interface Guidelines.GParted comes under the terms of the General Public License

Features
News (17 december)
Screenshots
Downloads
LiveCD
LiveUSB

SystemRescueCd

SystemRescueCd
Description: SystemRescueCd is a Linux system on a bootable CD-ROM for repairing your system and recovering your data after a crash. It aims to provide an easy way to carry out admin tasks on your computer, such as creating and editing the partitions of the hard disk. It contains a lot of system utilities (parted, partimage, fstools, ...) and basic tools (editors, midnight commander, network tools). It is very easy to use: just boot the CDROM. The kernel supports most of the important file systems (ext2/ext3, reiserfs, reiser4, xfs, jfs, vfat, ntfs, iso9660), as well as network filesystems (samba and nfs).
If this is the first time you use SystemRescueCd, please read the Quick start guide (english)

System tools included
GNU Parted creates, resizes, moves, copies partitions, and filesystems (and more).
GParted GUI implementation using the GNU Parted library.
Partimage saves / restores partitions to an image file on another partition or to another system.
File systems tools (e2fsprogs, reiserfsprogs, reiser4progs, xfsprogs, jfsutils, ntfsprogs, dosfstools): format, resize, and debug an existing partition of a hard disk
Ntfs3g: enables read/write access to MS Windows NTFS partitions.
sfdisk saves / restores partition table (and more).
Test-disk tool to check and undelete partition, supports reiserfs, ntfs, fat32, ext2/3 and many others
Network tools (Samba, NFS, ping, nslookup, ...)
Browse the short system tools page for more details about the most important software included.
Browse the detailed package list for a full list of the packages.

Screenshots
download

XFS: A high-performance journaling filesystem

XFS: A high-performance journaling filesystem
SGI - Developer Central Open Source XFS
XFS combines advanced journaling technology with full 64-bit addressing and scalable structures and algorithms. This combination delivers the most scalable high-performance filesystem ever conceived.


Features


The XFS filesystem provides the following major features:


  • Quick Recovery

    The XFS journaling technology allows it to restart very quickly after an
    unexpected interruption, regardless of the number of files it is managing.
    Traditional filesystems must do special filesystem checks after an interruption,
    which can take many hours to complete. The XFS journaling avoids these lengthy
    filesystem checks.


  • Fast Transactions

    The XFS filesystem provides the advantages of journaling while minimizing the
    performance impact of journaling on read and write data transactions. Its
    journaling structures and algorithms are tuned to log the transactions rapidly.


    XFS uses efficient tree structures for fast searches and rapid space
    allocation. XFS continues to deliver rapid response times, even for directories
    with tens of thousands of entries.


  • Massive Scalability

    XFS is a full 64-bit filesystem, and thus is capable of handling filesystems
    as large as a million terabytes.

    263  = 9 x 1018 = 9 exabytes 


    A million terabytes is thousands of times larger than most large filesystems
    in use today. This may seem to be an extremely large address space, but it is
    needed to plan for the exponential disk density improvements observed in the
    storage industry in recent years. As disk capacity grows, not only does the
    address space need to be sufficiently large, but the structures and algorithms
    need to scale. XFS is ready today with the technologies needed for this
    scalability.


    XFS also continues to evolve to match the capabilities of the hardware it is
    being deployed on. Efficiency when dealing with large amounts (terabytes) of
    main memory and hence large numbers of active files and large amounts of cached
    file data are areas demanding continual improvements. Extending XFS to improve
    performance on large NUMA machines is also an area of active research and
    development.


  • Efficient Allocations

    XFS implements extremely sophisticated space management techniques.
    Efficiency in space management has been achieved through the use of variable
    sized extents, rather than the simple single-block-at-a-time mechanism of many
    other filesystems. XFS was the first filesystem to implement delayed space
    allocation for buffered writes, supports direct I/O, provides an optional
    realtime allocator, and is able to align allocations based on the geometry of
    the underlying storage device. The XFS allocator performs admirably in the
    presence of multiple parallel writers, and is renowned for its resistance to
    space fragmentation under such conditions.


  • Excellent Bandwidth

    XFS is capable of delivering very close to the raw I/O performance that the
    underlying hardware can provide. XFS has proven scalability on SGI Altix systems
    of multiple gigabytes-per-second on multiple terabyte filesystems.



Technical Specifications


Technology


Journaled 64-bit filesystem with guaranteed filesystem consistency.


Availability


XFS is available for Linux 2.4 and later Linux kernels.


Online Administration


XFS supports filesystem growth for mounted volumes, allows filesystem
"freeze" and "thaw" operations to support volume level snapshots, and provides
an online file defragmentation utility.


Quotas


XFS supports user and group quotas. XFS considers quota information as
filesystem metadata and uses journaling to avoid the need for lengthy quota
consistency checks after a crash. Project quota are now also supported, and
these can be used to provide a form of directory tree quota.


Extended Attributes


XFS implements fully journaled extended attributes. An extended attribute is
a name/value pair associated with a file. Attributes can be attached to all
types of inodes: regular files, directories, symbolic links, device nodes, and
so forth. Attribute values can contain up to 64KB of arbitrary binary data. XFS
implements three attribute namespaces: a user namespace available to all users,
protected by the normal file permissions; a system namespace, accessible only to
privileged users; and a security namespace, used by security modules (SELinux).
The system namespace can be used for protected filesystem meta-data such as
access control lists (ACLs) and hierarchical storage manager (HSM) file
migration status.


POSIX Access Control Lists (ACLs)


XFS supports the ACL semantics and interfaces described in the draft POSIX
1003.1e standard.


Maximum File Size


For Linux 2.4, the maximum accessible file offset is 16TB on 4K page size and
64TB on 16K page size. For Linux 2.6, when using 64 bit addressing in the block
devices layer (CONFIG_LBD), file size limit increases to 9 million terabytes (or
the device limits).


Maximum Filesystem Size


For Linux 2.4, 2 TB. For Linux 2.6 and beyond, when using 64 bit addressing
in the block devices layer (CONFIG_LBD) and a 64 bit platform, filesystem size
limit increases to 9 million terabytes (or the device limits). For these later
kernels on 32 bit platforms, 16TB is the current limit even with 64 bit
addressing enabled in the block layer.


Filesystem Block Size


The minimum filesystem block size is 512 bytes. The maximum filesystem block
size is the page size of the kernel, which is 4K on x86 architecture and is set
as a kernel compile option on the IA64 architecture (up to 64 kilobyte pages).
So, XFS supports filesystem block sizes up to 64 kilobytes (from 512 bytes, in
powers of 2), when the kernel page size allows it.


Filesystem extents (contiguous data) are configurable at file creation time
using xfsctl(3) and are multiples of the filesystem block size. Individual
extents can be up to 4 GB in size.


Physical Disk Sector Sizes Supported


512 bytes through to 32 kilobytes (in powers of 2), with the caveat that the
sector size must be less than or equal to the filesystem blocksize.


NFS Compatibility


With NFS version 3, 64-bit filesystems can be exported to other systems that
support the NFS V3 protocol. Systems that use NFS V2 protocol may access XFS
filesystems within the 32-bit limit imposed by the protocol.


Windows Compatibility


SGI uses the Open Source Samba server to export XFS filesystems to Microsoft
Windows systems. Samba speaks the SMB (Server Message Block) and CIFS (Common
Internet File System) protocols.


Backup/Restore


xfsdump and xfsrestore can be used for backup and restore of XFS file systems
to local/remote SCSI tapes or files. It supports dumping of extended attributes
and quota information. As the xfsdump format has been preserved and is now
endian neutral, dumps created on one platform can be restored onto an XFS
filesystem on another (different architectures, and even different operating
systems - IRIX to Linux, and vice-versa).


Support for Hierarchical Storage


The Data Management API (DMAPI/XDSM) allows implementation of hierarchical
storage management software with no kernel modifications as well as
high-performance dump programs without requiring "raw" access to the disk and
knowledge of filesystem structures.


Optional Realtime Allocator


XFS supports the notion of a "realtime subvolume" - a separate area of disk
space where only file data is stored. Space on this subvolume is managed using
the realtime allocator (as opposed to the default, B+ tree space allocator). The
realtime subvolume is designed to provide very deterministic data rates suitable
for media streaming applications.

Use RegExp to parse IP address (logfile) | VB.Net

Use Regular Expressions to parse IP address

Imports System
Imports System.Text
Imports System.Text.RegularExpressions


Public Class MainClass

Shared Sub Main()
Dim string1 As String = _
"04:03:27 127.0.0.0 www.java2s.com"

' time = one or more digits or colons
' followed by a space
' ip address = one or more digits or dots
' followed by space
' site = one or more characters
Dim regString As String = "(?<time>(\d\:)+)\s" & _
"(?<ip>(\d\.)+)\s" & _
"(?<site>\S+)"

Dim theReg As New Regex(regString)
Dim theMatches As MatchCollection = theReg.Matches(string1)

Dim theMatch As Match
For Each theMatch In theMatches
If theMatch.Length <> 0 Then
Console.WriteLine( _
"theMatch: {0}", _
theMatch.ToString( ))
Console.WriteLine( _
"time: {0}", _
theMatch.Groups("time"))
Console.WriteLine( _
"ip: {0}", _
theMatch.Groups("ip"))
Console.WriteLine( _
"site: {0}", _
theMatch.Groups("site"))
End If
Next theMatch
End Sub
End Class

ewbi.develops: Sparklines

ewbi.develops: Sparklines

Sparklines - Jon Galloway

Sparklines - Jon Galloway

Javascript Sparklines Library

Javascript Sparklines Library

Gavotte Ramdisk - Free virtual hardisk

Gavotte Ramdisk - Free virtual hardisk

Free Ramdisk for Windows Vista, XP, 2000 and 2003 Server

Free Ramdisk for Windows Vista, XP, 2000 and 2003 Server
Ramdisk or RAM-Disk is a virtual hard drive based on software abstraction that treats a segment of random access memory (RAM) as secondary storage which is similar to hard disks, except with advantage that ramdisk is a lot faster and access time is greatly improved. As there is no mechanical moving parts involved, there won’t be question of wear and tear too. Ramdisk has one obvious downside, that it’s volatile and not solid state. Contents in Ramdisk is stored in computer RAM, which will be lost when the power of computer is switched off.With these benefits and limit, ramdisk can be used to store frequently accessed yet less important temporary data to speed up the system performance, such as swap space for virtual memory, temporary files used for programs such as Internet Explorer, BT client, P2P eMule, compression utility, translation software and etc, frequently accessed data from a database or used to hold uncompressed programs for short periods. From privacy point of view, Ramdisk is also a working drive for decrypted version of encrypted document, as all trace of the data will be wiped and deleted once power off.
There are plenty of Ramdisk driver and software available, such as RamDisk9xME, RAMDiskXP, RAMDiskSE and RAMDiskVE from Cenatek, RamDisk and RamDisk Plus from SuperSpeed, RAMDisk Enterprise Lite and Full version plus 64 MB limited free RAMDiskbased on Microsoft Ramdisk below from QSoft, and Ramdisk.sys driver for Windows 2000 from Microsoft published under KB257405. However, most of these Ramdisk drivers either is not free, or limit in its functionality especially on the size on RAM-disk. Some not even support Windows Vista.
The following freeware RRamdisk.sys, originally written by Gavotte based on Microsoft’s Ramdisk.sys, and later being added a GUI interface by lyh728 is not only free to use, it also stable, doesn’t have size limitation, supports popular FAT16,FAT32, NTFS filesystems, and supports Windows 2000 operating system and above including Vista.
Download Gavotte Ramdisk with GUI (ramdisk.zip).
Alternative download link.
To use Ramdisk, the most important requirement is that the system has a lot of memory, much a lot than the size of Ramdisk that you intends to create. It works on system with minimum 256 MB RAM, where you’re recommended not to set Ramdisk with size more than 64 MB.

squid : Optimising Web Delivery - IP Cache API

squid : Optimising Web Delivery

Detailed Description
The IP cache is a built-in component of squid providing Hostname to IP-Number translation functionality and managing the involved data-structures. Efficiency concerns require mechanisms that allow non-blocking access to these mappings. The IP cache usually doesn't block on a request except for special cases where this is desired.


Functions
void ipcache_purgelru (void *voidnotused)
static int ipcacheParse (ipcache_entry *i, const char *inbuf)
void ipcache_nbgethostbyname (const char *name, IPH *handler, void *handlerData)
void ipcache_init (void)
void ipcacheRegisterWithCacheManager (CacheManager &manager)
const ipcache_addrs * ipcache_gethostbyname (const char *name, int flags)
void ipcacheInvalidate (const char *name)
void ipcacheInvalidateNegative (const char *name)
ipcache_addrs * ipcacheCheckNumeric (const char *name)
void ipcacheCycleAddr (const char *name, ipcache_addrs *ia)
void ipcacheMarkBadAddr (const char *name, IPAddress &addr)
void ipcacheMarkGoodAddr (const char *name, IPAddress &addr)
void ipcacheFreeMemory (void)
void ipcache_restart (void)
int ipcacheAddEntryFromHosts (const char *name, const char *ipaddr)
variable_list * snmp_netIpFn (variable_list *Var, snint *ErrP)

squid : Optimising Web Delivery - dnsserver

squid : Optimising Web Delivery

Detailed Description
Because the standard gethostbyname() library call blocks, Squid must use external processes to actually make these calls. Typically there will be ten dnsserver processes spawned from Squid. Communication occurs via TCP sockets bound to the loopback interface. The functions in dns.cc are primarily concerned with starting and stopping the dnsservers. Reading and writing to and from the dnsservers occurs in the IP and FQDN cache modules.

Command Line Interface
usage: dnsserver -Dhv -s nameserver
-D Enable resolver RES_DEFNAMES and RES_DNSRCH options
-h Help
-v Version
-s nameserver Specify alternate name server(s). 'nameserver'
must be an IP address, -s option may be repeated

Submit your site to Search Engines

Submit your site to Search Engines:
1. Submit to Google - http://www.google.com/addurl/
2. Submit to Yahoo - https://siteexplorer.search.yahoo.com/submit
3. Submit to MSN Live Search - http://search.msn.com.sg/docs/submit.aspx

Sunday, December 30, 2007

Google Chart GUI : Chart Generator

This is a GUI for the recently released Google Chart API

read more | digg story

Google Chart Generator

A script to generate immediatly chart using google chart apis.

read more | digg story

Blog This - simple editor using the Blogger JavaScript API

Blog This - simple editor using the Blogger JavaScript API

10 Free Microsoft Apps That Don’t Suck

Microsoft is not usually a company that gets associated with cool and free products. Google is more like it, it got Gmail, Google Reader, Docs and dozens of other useful services. Nonetheless, there are a bunch of FREE Microsoft tools that definitely worth a look at. While some of them are yet to be released, other have been around for a while

read more | digg story

On efficiently geo-referencing IPs with MaxMind GeoIP and MySQL GIS

On efficiently geo-referencing IPs with MaxMind GeoIP and MySQL GIS

Saturday, December 29, 2007

40 Unusual Websites you should Bookmark.

Undiscovered webservices that are original, rather unique, unusual, useful, free, and must-be bookmarked type. You won’t find any collaboration, storage or ToDo service here. Enjoy! A Must Read

read more | digg story

Gmail Craze: 30 + Tools and Hacks for Gmail

All for Gmail: handy Firefox extensions, best Greasemonkey scripts, some desktop tools and lots of useful tips. Take this Gmail thingie to another level. Enjoy

read more | digg story

5 “Disposable” Web Accounts to Keep Your Identity Safe

Fed up with spam? Tired of telemarketing calls? Feelin’ paranoid about identity theft? … Here you’ll find a bunch “throwaway” web tools that can help you out.

read more | digg story

100 Portable Apps for your USB Stick (both for Mac and Win)

Divided over 13 categories, incl games.

read more | digg story

40 Unusual Websites you should Bookmark.

Undiscovered webservices that are original, rather unique, unusual, useful, free, and must-be bookmarked type. You won’t find any collaboration, storage or ToDo service here. Enjoy! A Must Read

read more | digg story

5 “Disposable” Web Accounts to Keep Your Identity Safe

Fed up with spam? Tired of telemarketing calls? Feelin’ paranoid about identity theft? … Here you’ll find a bunch “throwaway” web tools that can help you out.

read more | digg story

Friday, December 28, 2007

Create Customized CSS Menus

The site provides lots of quality css menus that you can easily customize right there on the site and then download your custom menu,

read more | digg story

Create Customized CSS Menus

The site provides lots of quality css menus that you can easily customize right there on the site and then download your custom menu,

read more | digg story

Thursday, December 27, 2007

Using the right version of MSXML in Internet Explorer

Microsoft XML Team's WebLog : Using the right version of MSXML in Internet Explorer


Try MSXML6 and fallback to MSXML3 – MSXML6 has some improvements that aren’t in MSXML3 such as support for XSD schema, and improved stability, performance, and security. So your app may try out MSXML6 if it is on the box and then “fallback” gracefully. Just remember to test your app with MSXML6 and with MSXML3 so you aren’t surprised when you release your application. Here’s a quick example:

if (Web.Application.get_type() == Web.ApplicationType.InternetExplorer) {
var progIDs = [ 'Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.3.0'];

for (var i = 0; i < progIDs.length; i++) {
try {
var xmlDOM = new ActiveXObject(progIDs[i]);
return xmlDOM;
}
catch (ex) {
}
}

return null;
}

Rush Hour 3 | Video | KINO.DE

Rush Hour 3 Video KINO.DE

Wednesday, December 26, 2007

DHTML: Draw Line, Ellipse, Oval, Circle, Polyline, Polygon, Triangle with JavaScript

DHTML: Draw Line, Ellipse, Oval, Circle, Polyline, Polygon, Triangle with JavaScript

ExplorerCanvas

ExplorerCanvas

XML HTTP Performance and Caching

Emil’s Chronicle » XML HTTP Performance and Caching

UDP: Server receives packets from a client, then echoes packets back to clients | VB.Net

UDP: Server receives packets from a client, then echoes packets back to clients VB.Net



Imports System.Threading
Imports System.Net.Sockets
Imports System.IO
Imports System.Net


Public Class MainClass
Shared Dim client As UdpClient
Shared Dim receivePoint As IPEndPoint

Public Shared Sub Main()

client = New UdpClient(5000)

receivePoint = New IPEndPoint(New IPAddress(0), 0)

Dim readThread As Thread = New Thread(New ThreadStart(AddressOf WaitForPackets))

readThread.Start() ' wait for packets
End Sub

Shared Public Sub WaitForPackets()
While True
Dim data As Byte() = client.Receive(receivePoint)
Console.WriteLine("Packet received:" & _
vbCrLf & "Length: " & data.Length & vbCrLf & _
"Containing: " & _
System.Text.Encoding.ASCII.GetString(data) )

Console.WriteLine("Echo data back to client...")

client.Send(data, data.Length, receivePoint)
Console.WriteLine("Packet sent")
End While
End Sub

End Clas