Winsock Component - Using in C#
Sending e-mail, using OstroSoft Winsock Component (OSWinsock.dll)
Download project source code

Minimum requirements: C#, OSWinsock.dll*
* If you don't have OstroSoft Winsock Component, see installation instructions

1. In Visual Studio.NET create new C# Windows Application
2. Click on Project menu and select "Add Reference"
3. In "Add Reference" dialog box click on COM tab and select OSWinsock. Click OK to save a new reference.
4. Enter the following code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace oswinsck_csharp
{
public class frmMain : System.Windows.Forms.Form
{
internal System.Windows.Forms.Button cmdView;
internal System.Windows.Forms.TextBox txtSource;
internal System.Windows.Forms.TextBox txtURL;
internal System.Windows.Forms.Label Label1;
internal System.Windows.Forms.CheckBox chkProxy;
internal System.Windows.Forms.TextBox txtProxy;
private System.ComponentModel.Container components = null;
public frmMain()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private void cmdView_Click(object sender, System.EventArgs e)
{
int nPort = 80;
string sSource = "";
string sRequest = "";
string sPage = "";
string sServer = "";
int nConnected = 0;
if (txtURL.Text != "")
{
sServer = txtURL.Text;
if (sServer.IndexOf("://") > 0)
sServer = sServer.Substring(sServer.IndexOf("://") + 3);
if (sServer.IndexOf("/") > 1)
{
sPage = sServer.Substring(sServer.IndexOf("/"));
sServer = sServer.Substring(0, sServer.IndexOf("/"));
if (sPage.IndexOf("#") > 1 )
sPage = sPage.Substring(0, sPage.IndexOf("#"));
}
else
sPage = "/";
if (sServer.IndexOf(":") > 1) {
nPort =
Convert.ToInt32(sServer.Substring(sServer.IndexOf(":", 0)));
sServer = sServer.Substring(0, sServer.IndexOf(":"));
}
OSWINSCK.TCP wsTCP = new OSWINSCK.TCP();
if (txtProxy.Text != "")
{
sRequest = "GET http://" + sServer + sPage + " HTTP/1.0\r\n";
nConnected = wsTCP.Connect(txtProxy.Text, 80);
}
else
{
sRequest = "GET " + sPage + " HTTP/1.0\r\n";
nConnected = wsTCP.Connect(sServer, nPort);
}
if (nConnected == 0) {
wsTCP.SendData (sRequest + "\r\n");
wsTCP.Sleep (1000);
sSource = wsTCP.GetData();
wsTCP.Disconnect();
}
wsTCP = null;
txtSource.Text=sSource;
}
}
}
}
|