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

Create a new Class library project in Visual Studio .NET, set the namespace to p2pfirewall and the class as tunnel. Since the class will be remoted, we need to derive the tunnel class from System.MarshallByRef Object.

The post methods (postRequest, postResponse) are fairly straightforward. An SQL query is constructed that inserts a new row into the corresponding table, and then executed.

The check methods are slightly more complex. checkRequests for instance, pulls the first pending request from the database that is marked for the attention of the peer making the call. That request is then deleted from the database. checkResponses is similar, where the first row from the responses table that have come from the requested peer, and contains the correct file is returned.

C#

using System;

using System.Data.OleDb;

namespace p2pfirewall

{

    public class tunnel : System.MarshalByRefObject

    {

            private string DSN = "Provider=Microsoft.Jet.OLEDB.4.0;" +

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

            public void postRequest(string requestingPeer, string filename,

                                      string respondingPeer)

            {                      

                    string SQL;

                    SQL = "insert into requests";

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

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

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

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

                    nonQuery(SQL,DSN);

            }

            public void postResponse(string respondingPeer, string filename,

                                     string fileContents,string requestingPeer)

            {

                    string SQL;

                    SQL = "insert into responses ";

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

                    SQL += " values (";

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

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

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

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

                    nonQuery(SQL,DSN);

            }

            public string checkRequests(string peer)

            {

                    string SQL;

                    string filename;

                    SQL = "select top 1 * from requests where ";

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

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

                    // don't return the same request twice.

                    SQL = "delete from requests where ";

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

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

                    nonQuery(SQL,DSN);

                    return filename;

            }

            public string checkResponse(string respondingPeer,

                                          string filename)

            {

                    string SQL;

                    SQL = "select top 1 * from responses where ";

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

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

                    return Query("fileContents",SQL,DSN);

            }

           

    }

}

Page 1  Page 3 



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