//Dll//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO ;
using System.Diagnostics;
namespace dll1
{
public class Class1:MarshalByRefObject
{
public DriveInfo[] get()
{
DriveInfo[] drv = DriveInfo.GetDrives();
return drv;
}
public void str(string msg)
{
Process.Start(msg);
}
}
}
Thursday, August 6, 2009
Chat clint in consol
//Client//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Client
{
class Program
{
private static TcpClient client=new TcpClient ();
private static NetworkStream ns;
static void Main(string[] args)
{
try
{
client .Connect ("localhost", 4545);
Console.WriteLine("Connected with server");
ns = client.GetStream();
Thread t = new Thread(new ThreadStart(readserverdata));
t.Start();
while (client.Connected)
{
string data = Console.ReadLine();
byte[] bytedata = Encoding.ASCII.GetBytes(data);
ns.Write (bytedata,0, bytedata.Length);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
private static void readserverdata()
{
while (client.Connected )
{
try
{
byte []buffer=new byte[255];
ns.Read (buffer ,0,255);
string data=Encoding .ASCII .GetString (buffer );
Console .WriteLine ("server:"+data );
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Client
{
class Program
{
private static TcpClient client=new TcpClient ();
private static NetworkStream ns;
static void Main(string[] args)
{
try
{
client .Connect ("localhost", 4545);
Console.WriteLine("Connected with server");
ns = client.GetStream();
Thread t = new Thread(new ThreadStart(readserverdata));
t.Start();
while (client.Connected)
{
string data = Console.ReadLine();
byte[] bytedata = Encoding.ASCII.GetBytes(data);
ns.Write (bytedata,0, bytedata.Length);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
private static void readserverdata()
{
while (client.Connected )
{
try
{
byte []buffer=new byte[255];
ns.Read (buffer ,0,255);
string data=Encoding .ASCII .GetString (buffer );
Console .WriteLine ("server:"+data );
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
Chat server in console
// chat server//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace server
{
class Program
{
private static TcpListener ser;
private static Socket sock;
static void Main(string[] args)
{
try
{
IPAddress localaddr = IPAddress.Parse("127.0.0.1");
ser = new TcpListener(localaddr, 4545);
ser.Start();
Console.WriteLine("Server Started");
sock = ser.AcceptSocket();
Console.WriteLine("Client connected");
Thread t = new Thread(new ThreadStart(readclientdata));
t.Start();
while (sock.Connected)
{
string data = Console.ReadLine();
byte[] bytedata = Encoding.ASCII.GetBytes(data);
sock.Send(bytedata, bytedata.Length, 0);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
private static void readclientdata()
{
while (sock.Connected )
{
try
{
byte []buffer=new byte[255];
sock .Receive (buffer ,255,0);
string data=Encoding .ASCII .GetString (buffer );
Console .WriteLine ("client:"+data );
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace server
{
class Program
{
private static TcpListener ser;
private static Socket sock;
static void Main(string[] args)
{
try
{
IPAddress localaddr = IPAddress.Parse("127.0.0.1");
ser = new TcpListener(localaddr, 4545);
ser.Start();
Console.WriteLine("Server Started");
sock = ser.AcceptSocket();
Console.WriteLine("Client connected");
Thread t = new Thread(new ThreadStart(readclientdata));
t.Start();
while (sock.Connected)
{
string data = Console.ReadLine();
byte[] bytedata = Encoding.ASCII.GetBytes(data);
sock.Send(bytedata, bytedata.Length, 0);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
private static void readclientdata()
{
while (sock.Connected )
{
try
{
byte []buffer=new byte[255];
sock .Receive (buffer ,255,0);
string data=Encoding .ASCII .GetString (buffer );
Console .WriteLine ("client:"+data );
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
Rpc client
//Rpc client//
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.IO;
using dll1;
namespace rpcclients
{
public partial class Form1 : Form
{
Class1 c = (Class1)Activator.GetObject(typeof(Class1), "http://localhost:5000/test");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] dr = c.get();
foreach (DriveInfo d in dr)
{
listBox1.Items.Add(d);
}
}
private void button2_Click(object sender, EventArgs e)
{
c.str(textBox1.Text);
}
}
}
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.IO;
using dll1;
namespace rpcclients
{
public partial class Form1 : Form
{
Class1 c = (Class1)Activator.GetObject(typeof(Class1), "http://localhost:5000/test");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] dr = c.get();
foreach (DriveInfo d in dr)
{
listBox1.Items.Add(d);
}
}
private void button2_Click(object sender, EventArgs e)
{
c.str(textBox1.Text);
}
}
}
Rpc Server
//Serever//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using dll1;
namespace rpcservers
{
class Program
{
static void Main(string[] args)
{
HttpServerChannel hts = new HttpServerChannel(5000);
ChannelServices.RegisterChannel(hts);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1), "test", WellKnownObjectMode.SingleCall );
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using dll1;
namespace rpcservers
{
class Program
{
static void Main(string[] args)
{
HttpServerChannel hts = new HttpServerChannel(5000);
ChannelServices.RegisterChannel(hts);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1), "test", WellKnownObjectMode.SingleCall );
Console.Read();
}
}
}
Notpad
//Notpad//
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.IO;
namespace Notpad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog fd = new OpenFileDialog();
fd.ShowDialog();
FileStream fs = new FileStream(fd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(fs);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog sd = new SaveFileDialog();
sd.ShowDialog();
FileStream fs1 = new FileStream(sd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(richTextBox1.Text);
sw.Close();
fs1.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void newToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
if (richTextBox1.Text != "")
{
DialogResult dr = MessageBox.Show("Save now", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
SaveFileDialog sd = new SaveFileDialog();
sd.ShowDialog();
//richTextBox1.SaveFile(sd.FileName);
FileStream fs1 = new FileStream(sd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(richTextBox1.Text);
sw.Close();
fs1.Close();
}
else
{
richTextBox1.Text = "";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("Save now", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
SaveFileDialog sd = new SaveFileDialog();
sd.ShowDialog();
//richTextBox1.SaveFile(sd.FileName);
FileStream fs1 = new FileStream(sd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(richTextBox1.Text);
sw.Close();
fs1.Close();
}
else
{
richTextBox1.Text = "";
}
}
private void aboutUsToolStripMenuItem_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"E:\\CCSIT\Notpad\About.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(fs);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
fs.Close();
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
}
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.IO;
namespace Notpad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog fd = new OpenFileDialog();
fd.ShowDialog();
FileStream fs = new FileStream(fd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(fs);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog sd = new SaveFileDialog();
sd.ShowDialog();
FileStream fs1 = new FileStream(sd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(richTextBox1.Text);
sw.Close();
fs1.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void newToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
if (richTextBox1.Text != "")
{
DialogResult dr = MessageBox.Show("Save now", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
SaveFileDialog sd = new SaveFileDialog();
sd.ShowDialog();
//richTextBox1.SaveFile(sd.FileName);
FileStream fs1 = new FileStream(sd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(richTextBox1.Text);
sw.Close();
fs1.Close();
}
else
{
richTextBox1.Text = "";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("Save now", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
SaveFileDialog sd = new SaveFileDialog();
sd.ShowDialog();
//richTextBox1.SaveFile(sd.FileName);
FileStream fs1 = new FileStream(sd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(richTextBox1.Text);
sw.Close();
fs1.Close();
}
else
{
richTextBox1.Text = "";
}
}
private void aboutUsToolStripMenuItem_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"E:\\CCSIT\Notpad\About.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader sr = new StreamReader(fs);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
fs.Close();
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
}
Calculator
// CALCULATOR//
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;
namespace calculator
{
public partial class Form1 : Form
{
float z,y,m;
char opr;
Boolean t = true;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "1";
}
else
{
textBox1.Text = textBox1.Text + "1";
}
}
private void button2_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "2";
}
else
{
textBox1.Text = textBox1.Text + "2";
}
}
private void button3_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "3";
}
else
{
textBox1.Text = textBox1.Text + "3";
}
}
private void button4_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "4";
}
else
{
textBox1.Text = textBox1.Text + "4";
}
}
private void button5_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "5";
}
else
{
textBox1.Text = textBox1.Text + "5";
}
}
private void button6_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "6";
}
else
{
textBox1.Text = textBox1.Text + "6";
}
}
private void button7_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "7";
}
else
{
textBox1.Text = textBox1.Text + "7";
}
}
private void button8_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "8";
}
else
{
textBox1.Text = textBox1.Text + "8";
}
}
private void button9_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "9";
}
else
{
textBox1.Text = textBox1.Text + "9";
}
}
private void button10_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "0";
}
else
{
textBox1.Text = textBox1.Text + "0";
}
}
private void button13_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '+';
}
private void button14_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '-';
}
private void button15_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '*';
}
private void button16_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '/';
}
private void button12_Click(object sender, EventArgs e)
{
t = false;
z = float.Parse(textBox1.Text);
switch (opr)
{
case '+': float p = y + z;
textBox1.Text = p.ToString();
break;
case '-': float q = y - z;
textBox1.Text = q.ToString();
break;
case '*': float r = y * z;
textBox1.Text = r.ToString();
break;
case '/': float s = y / z;
textBox1.Text = s.ToString();
break;
}
}
private void button11_Click_1(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + ".";
}
else
{
textBox1.Text = textBox1.Text + ".";
}
}
private void button17_Click(object sender, EventArgs e)
{
m = float.Parse(textBox1.Text);
textBox1.Text = "";
}
private void button18_Click(object sender, EventArgs e)
{
textBox1.Text = m.ToString();
}
}
}
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;
namespace calculator
{
public partial class Form1 : Form
{
float z,y,m;
char opr;
Boolean t = true;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "1";
}
else
{
textBox1.Text = textBox1.Text + "1";
}
}
private void button2_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "2";
}
else
{
textBox1.Text = textBox1.Text + "2";
}
}
private void button3_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "3";
}
else
{
textBox1.Text = textBox1.Text + "3";
}
}
private void button4_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "4";
}
else
{
textBox1.Text = textBox1.Text + "4";
}
}
private void button5_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "5";
}
else
{
textBox1.Text = textBox1.Text + "5";
}
}
private void button6_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "6";
}
else
{
textBox1.Text = textBox1.Text + "6";
}
}
private void button7_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "7";
}
else
{
textBox1.Text = textBox1.Text + "7";
}
}
private void button8_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "8";
}
else
{
textBox1.Text = textBox1.Text + "8";
}
}
private void button9_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "9";
}
else
{
textBox1.Text = textBox1.Text + "9";
}
}
private void button10_Click(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + "0";
}
else
{
textBox1.Text = textBox1.Text + "0";
}
}
private void button13_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '+';
}
private void button14_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '-';
}
private void button15_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '*';
}
private void button16_Click(object sender, EventArgs e)
{
y = float.Parse(textBox1.Text);
textBox1.Text = "";
opr = '/';
}
private void button12_Click(object sender, EventArgs e)
{
t = false;
z = float.Parse(textBox1.Text);
switch (opr)
{
case '+': float p = y + z;
textBox1.Text = p.ToString();
break;
case '-': float q = y - z;
textBox1.Text = q.ToString();
break;
case '*': float r = y * z;
textBox1.Text = r.ToString();
break;
case '/': float s = y / z;
textBox1.Text = s.ToString();
break;
}
}
private void button11_Click_1(object sender, EventArgs e)
{
if (t == false)
{
textBox1.Text = "";
t = true;
textBox1.Text = textBox1.Text + ".";
}
else
{
textBox1.Text = textBox1.Text + ".";
}
}
private void button17_Click(object sender, EventArgs e)
{
m = float.Parse(textBox1.Text);
textBox1.Text = "";
}
private void button18_Click(object sender, EventArgs e)
{
textBox1.Text = m.ToString();
}
}
}
Subscribe to:
Posts (Atom)
