Client Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
namespace HAN
{
public partial class multinet : Form
{
Connection cn = new Connection();
SqlCommand cmd;
string rand, pub, enc,label;
int hc;
int rd;
TcpClient clientSocket = default(TcpClient);
string message;
public multinet(string s, string s1, string s2, string s3)
{
InitializeComponent();
label = s.ToString();
rand = s1.ToString();
pub = s2.ToString();
enc = s3.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
cn.con.Open();
}
public void msg(string mesg)
{
listBox1.Items.Add(">> " + mesg);
}
private void button1_Click(object sender, EventArgs e)
{
message = textBox1.Text.ToString();
try
{
Int32 port = 500;
TcpClient client = new TcpClient(textBox2.Text.ToString(),port);
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
listBox1.Items.Add(String.Format("Sent: {0}", message));
data = new Byte[256];
String responseData = String.Empty;
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
listBox1.Items.Add(String.Format("Validation Sucess: {0}", responseData));
stream.Close();
client.Close();
}
catch (ArgumentNullException an)
{
listBox1.Items.Add(String.Format("ArgumentNullException: {0}", an));
}
catch (SocketException se)
{
listBox1.Items.Add(String.Format("SocketException: {0}", se));
}
}
private void button2_Click(object sender, EventArgs e)
{
rd = Convert.ToInt32(rand);
int pubk = Convert.ToInt32(pub);
hc = rd * pubk;
string hcd = Convert.ToString(hc);
MessageBox.Show("Enter The Key to Transfer as Ittration 1"+hcd.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
split slt = new split(label.ToString(), rand.ToString(), pub.ToString(), enc.ToString());
slt.Show();
this.Close();
}
private void button7_Click(object sender, EventArgs e)
{
MessageBox.Show("The Shared Key is"+label.ToString());
}
int bc;
private void button4_Click(object sender, EventArgs e)
{
int nsx = hc * rd;
bc = 2 * nsx;
string bcn = Convert.ToString(bc);
MessageBox.Show("Enter The Key to Transfer as Ittration 2" + bcn.ToString());
}
int neibur;
private void button5_Click(object sender, EventArgs e)
{
int ncw = bc * rd;
neibur = 2 * ncw;
string ncd = Convert.ToString(neibur);
MessageBox.Show("Enter The Key to Transfer as Ittration 3" + ncd.ToString());
}
private void button6_Click(object sender, EventArgs e)
{
int cc = neibur * 2;
string cc1 = Convert.ToString(cc);
MessageBox.Show("Enter The Key to Transfer as Ittration 4" + cc1.ToString());
}
}
}
Server Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
namespace serve
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
backgroundWorker1.WorkerSupportsCancellation = true;
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
if (backgroundWorker1.IsBusy != true)
{
backgroundWorker1.RunWorkerAsync();
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
if ((worker.CancellationPending == true))
{
e.Cancel = true;
}
else
{
try
{
Int32 port = 500;
IPAddress localAddr = IPAddress.Parse("192.168.1.7");
TcpListener server = new TcpListener(IPAddress.Any, port);
server.Start();
Byte[] bytes = new Byte[256];
String data = null;
while (true)
{
backgroundWorker1.ReportProgress(0, "Waiting for a connection... ");
TcpClient client = server.AcceptTcpClient();
backgroundWorker1.ReportProgress(0, "Connected!");
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
backgroundWorker1.ReportProgress(0, String.Format("Received: {0}", data));
data = String.Format("I Have Received Your Packet: {0}", data);
byte[] mssg = System.Text.Encoding.ASCII.GetBytes(data);
stream.Write(mssg, 0, mssg.Length);
backgroundWorker1.ReportProgress(0, String.Format("Sent: {0}", data));
}
client.Close();
}
}
catch (SocketException se)
{
backgroundWorker1.ReportProgress(0, String.Format("SocketException: {0}", se));
}
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
listBox1.Items.Add(e.UserState);
}
}
}
It was done by myself only with some emergency case we are getting your help sir Thank You...Thanks fr Your Motivation...