Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
Available now!
Buy at Amazon US or
Buy at Amazon UK



Articles

1.Windows API reference
2.HTML to WML Converter
3.Webcam streaming in VB.NET
4.Remoting with firewalls
5.RSA from first principles
6.Key & MouseLogger in .NET
7.Networking Resource Kit for .NET
8.Automatic Reboot with .NET
9.XAML Schema
10.Migrating VB6 Winsock to VB.NET
11.Migrating C++ sockets to C#
12.RFC Reference guide
13.Lingua - Localization webservice
14.COM Reference guide
15.WMI Reference guide
16.SQL stored procedures
17.TCP & UDP port reference
18..NET Framework reference
19.Ethernet Type codes
21.MAC address assignments
22.DLL entry point reference
23.WHOIS server list
24. Turing Numbers
25. Boost SQL performance
26. Progress Bar in ASP.NET
27. OleDb WebService
27. Internet Explorer

Contact us

VB.NET

Imports System

Imports System.Data.OleDb

 

Namespace p2pfirewall

 Public Class tunnel

  Inherits System.MarshalByRefObject

  Dim DSN as string = "Provider=Microsoft.Jet.OLEDB.4.0;" + _

                       "Data Source=C:\filetransfers.mdb";

  Public  Sub postRequest(ByVal requestingPeer As String, ByVal _

                     filename As String, ByVal respondingPeer As String)     Dim SQL As String

    SQL = "insert into requests "

    SQL = SQL +  "(requester,filename,respondent) values ("

    SQL = SQL + "'" + requestingPeer + "',"

    SQL = SQL + "'" + filename + "',"

    SQL = SQL + "'" + respondingPeer + "')"

    nonQuery(SQL,DSN)

   End Sub

   Public  Sub postResponse(ByVal respondingPeer As String, _

    ByVal filename As String, ByVal fileContents As String, _

    ByVal requestingPeer As String)

     Dim SQL As String

      SQL = "insert into responses "

      SQL = SQL +  "((requester,fileContents,filename,respondent) values ("

      SQL = SQL +  "'" + requestingPeer + "',"

      SQL = SQL +  "'" + fileContents + "',"

      SQL = SQL +  "'" + filename + "',"

      SQL = SQL +  "'" + respondingPeer + "')"

      nonQuery(SQL,DSN)

     End Sub

   

    Public Function checkRequests(ByVal peer As String) As String

      Dim SQL As String

      Dim filename As String

      SQL = "select top 1 * from requests where "

      SQL = SQL +  " respondent='" + peer + "'"

      filename = Query("filename",SQL,DSN)

      ' don't return the same request twice.

     

      SQL = "delete from requests where "

       SQL = SQL +  " respondent='" + peer + "' and "

       SQL = SQL +  " filename='" + filename + "'"

       nonQuery(SQL,DSN)

       Return filename

    End Function

   

    Public Function checkResponse(ByVal respondingPeer As String, _

                              ByVal filename As String) As String

     Dim SQL As String

     SQL = "select top 1 * from responses where "

     SQL = SQL + " respondent='" + respondingPeer + "' and "

     SQL = SQL + " filename='" + filename + "'"

     Return Query("fileContents",SQL,DSN)

    End Function

 

    End Class

End Namespace

This class will be used in remoting, so therefore it must inherit from System.MarshalByRefObject. More information on this can be seen in the web services chapter. The public methods will be exposed to the client, but not the private methods and properties. The private string variable DSN is used to determine the location and type of the local database. This information is not relevant to the remote client.

Going through the functions one by one, let’s look at postRequest first. What the function does is it adds a new row into the request table, populating the requester, filename and respondent fields. It calls the nonQuery function, which as we shall see later is used to run statements against the database that do not return result sets.  

PostResponse is quite similar to PostRequest in that it adds a new row into the response table, populating the requester, fileContents, filename, and respondent fields. Once again, it calls the nonQuery function to process the statement.

CheckRequests performs two functions. Firstly it retrieves the last row in the requests table that pertains to a particular specified peer. It does this by executing a select statement against the requests table in the database, filtering by respondent. The second task performed by this function is to remove rows in the requests table pertaining to a particular peer. This prevents requests been handled more than once. This action is performed by the nonQuery function processing a SQL delete statement.

To complete the class, we need to implement the Query and nonQuery methods. These are taken from chapter 2, with some modification to the Query method, such that it returns a string that corresponds to the specified field as returned in the first row of data.

The fourth function, checkResponse reads the topmost row from the responses table that pertains to the specified peer. It returns the filecCntents field to the calling function.

Page 2  Page 4 



Google

Copyright 2012 Open Merchant Account Ltd.
Free SMS UK Free SMS Ireland SMS Gratis Norway SMS Gratis Sverige Ilmainen SMS Suomi SMS Gratis Danmark SMS Tasuta Eestisse SMS Nemokamai Lietuva SMS Bezmaksas Latviju Darmowe smsy Polska SMS Zdarma Ceské SMS Zdarma Slovensko SMS Gratis Deutschland SMS Gratis Schweiz SMS Gratis Österreich SMS Gratuit Belgique SMS Gratis Nederland SMS Gratuit France SMS Gratis Espańa SMS Gratis Portugal Free SMS South Africa Free SMS USA SMS Percuma Malaysia Free SMS Hong Kong