Posted on June 25, 2008 by Garbage Collector
MyPacket.cs
CSocketPacket.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace MyPacket
{
public class CSocketPacket
{
public System.Net.Sockets.Socket thisSocket;
public byte[] dataBuffer = new byte[100];
}
}
TcpSpecificPacket.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
namespace MyPacket
{
public class TcpSpecificPacket
{
public TcpClient thisClient;
public byte[] dataBuffer = new byte[100];
}
}
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
Async Client
Designer
namespace MyAsyncClient
{
partial class MyAsyncClientForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtPort;
private System.Windows.Forms.Button cmdSend;
private System.Windows.Forms.TextBox textBoxArrived;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button buttonConnect;
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.TextBox textBoxSend;
private System.Windows.Forms.TextBox txtIPAddr;
private System.ComponentModel.IContainer components = null;
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support – do not modify
/// the contents [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
Async Server
Designer
namespace MyAsyncServer
{
partial class MyAsyncServerForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Windows.Forms.Label labelPort;
private System.Windows.Forms.TextBox txtPortNo;
private System.Windows.Forms.Button buttonListen;
private System.Windows.Forms.TextBox textBoxReceived;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBoxSend;
private System.Windows.Forms.Button buttonSend;
private System.ComponentModel.IContainer components = null;
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support – do not modify
/// the contents of this method with the code [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
LockMutex.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace First
{
public class LockMutex
{
FileStream resource = null;
public LockMutex(String pathToFile)
{
resource = new FileStream(pathToFile, FileMode.Create, FileAccess.ReadWrite);
}
public void Read() {
//lock (resource) – am comentat liniile astea pentru a permite cititorilor accesul in paralel
// {
int thId = Thread.CurrentThread.ManagedThreadId;
resource.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(resource);
String s = sr.ReadToEnd();
Console.WriteLine(thId.ToString() + ” read : ” + s);
// }
}
public [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
3 projects: Main project, Reader, Writer.
MainProject, Program.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace MainProject
{
class Program
{
static void Main(string[] args)
{
FileStream fs = new FileStream(“test.txt”, FileMode.Create);
fs.Close();
Console.WriteLine(“Current context :” + AppDomain.CurrentDomain.Id);
AppDomain dw = AppDomain.CreateDomain(“Writers domain”);
AppDomain dr = AppDomain.CreateDomain(“Readers domain”);
for (int i = 0; i < 20; i++)
{
int opt = new Random().Next(2);
if (opt == 0)
{
dw.ExecuteAssembly(@”..\..\..\Reader\bin\Debug\Reader.exe”);
}
else {
dr.ExecuteAssembly(@”..\..\..\Writer\bin\Debug\Writer.exe”);
}
}
Console.WriteLine(“>>> Press any key to exit… <<<”);
Console.ReadKey();
}
}
}
Reader, [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.NetworkInformation;
using System.Xml;
namespace NetworkInformation
{
class Program
{
static void Main(string[] args)
{
IPGlobalProperties props = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] interfete = NetworkInterface.GetAllNetworkInterfaces();
//creez fisier XML
XmlTextWriter textWriter = new XmlTextWriter(@”C:\Documents and Settings\admin\Desktop\SD\networkInfo.xml”, null);
//deschid pentru a scrie
textWriter.WriteStartDocument();
//scriu un comentariu in fisierul XML
textWriter.WriteComment(“Interfete retea pentru ” + props.HostName);
//primul element
textWriter.WriteStartElement(“host”);
foreach (NetworkInterface interfata in interfete)
{
IPInterfaceProperties ipprop = interfata.GetIPProperties();
//begin interface
textWriter.WriteStartElement(“interface”);
//attribute
textWriter.WriteAttributeString(“name”, interfata.Name);
textWriter.WriteStartElement(“description”);
textWriter.WriteString(interfata.Description);
textWriter.WriteEndElement();
textWriter.WriteStartElement(“type”);
textWriter.WriteString(interfata.NetworkInterfaceType.ToString());
textWriter.WriteEndElement();
if (interfata.NetworkInterfaceType == NetworkInterfaceType.Loopback)
continue;
textWriter.WriteStartElement(“viteza”);
textWriter.WriteString(interfata.Speed + “bps”);
textWriter.WriteEndElement();
textWriter.WriteStartElement(“stare”);
textWriter.WriteString(interfata.OperationalStatus.ToString());
textWriter.WriteEndElement();
textWriter.WriteStartElement(“adresaFizica”);
textWriter.WriteString(interfata.GetPhysicalAddress().ToString());
textWriter.WriteEndElement();
textWriter.WriteStartElement(“sufixDNS”);
textWriter.WriteString(ipprop.DnsSuffix);
textWriter.WriteEndElement();
textWriter.WriteStartElement(“adreseIP”);
UnicastIPAddressInformationCollection adreseIP [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
Careful
Program.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace Pr2
{
class Program
{
public delegate void threadDelegate(string message);
static public event threadDelegate unEvent;
static void Main(string[] args)
{
bool dirValid = false;
string path = “”;
string responsePrompt=””;
while (!dirValid && path != “q”)
{
Console.WriteLine(“\nIntroduceti calea spre director (sau q pentru a iesi din bucla): “);
path = Console.ReadLine();
dirValid = dirExists(path);
if (dirValid && dirIsEmpty(path))
{
Console.WriteLine(“\nDirectorul a fost gasit dar este gol, [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
Carefull
Program.cs, Differ.cs
Program.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using System.Xml.Serialization;
namespace p1exam
{
class Program
{
static string path1 = “f1.txt”;
static string path2 = “f2.txt”;
static int size = 0;
static int random = 0;
static int cat = 0;
static int rest = 0;
static List<Differ> colectie = new List<Differ>();
static Differ diferit = null;
static FileStream f1 ;
static FileStream f2;
static object obj = new object();
internal class douaValori
{
public [...]
Filed under: Samples | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
Default.aspx
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Procesare String</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div style=”border:solid 1px #ccc;padding:10px;width:500px;height:500px;position:relative; background-color:#eee”>
<!– String Label –>
<asp:Label ID=”labelString” runat=”server” Style=”z-index:102;font-family:Arial; font-size:small;” Text=”String:”></asp:Label>
<br />
<!– Text Input –>
<asp:TextBox ID=”textBox” runat=”server” Style=”z-index:105;font-family:Arial; font-size:small;” Width=”256px”></asp:TextBox>
<!– Validare Text Input–>
<asp:CustomValidator ID=”ValidateText” runat=”server” ControlToValidate=”textBox” ErrorMessage=”Nu este text!” OnServerValidate=”ValidateText_ServerValidate” Style=”z-index:108;”>
</asp:CustomValidator>
<br /><br />
<!– Tip [...]
Filed under: Samples | Tagged: web application | Leave a Comment »
Posted on June 25, 2008 by Garbage Collector
Windows Application
Form1.cs, Form1.Designer.cs, Program.cs
Form1.Designer.cs
namespace ex2
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name=”disposing”>true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support [...]
Filed under: Samples | Leave a Comment »