C#

C# İphone WebBrowser

14. January 2010

Evet arkadaşlar bir web  browser projesi  yapıyordum nasıl bişey olsun derken bende iphone web browser  uygulaması  yazdım :) umarım  işe yarar sizlerde  yeni  eklentiler yazabilirsiniz sade  bir görüm oldu ama kullanılır :)

  Source code = İphoneİpaDownloadManager.rar (566,07 kb)

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace İphoneİpaDownloadManager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(txtara.Text);
            txtara.Text = "";
            txtara.Focus();
        }

        private void Form1_Load_1(object sender, EventArgs e)
        {

            try
            {
                cmblist.Items.Clear();
                StreamReader srRead = new StreamReader(@"adresler.txt");
                while (srRead.EndOfStream == false)
                {
                    cmblist.Items.Add(srRead.ReadLine().ToString());
                }
                srRead.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show("Hatalı Yükleme !\n\n" + ex.Message);
            }

        }

        private void cmblist_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            webBrowser1.Navigate(cmblist.Text);
            txtara.Text = "";
            txtara.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmadres adrs = new frmadres();

            adrs.ShowDialog();

        }

        private void btnfwrd_Click_1(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        private void btnback_Click_1(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void btnhome_Click_1(object sender, EventArgs e)
        {
            webBrowser1.GoHome();
        }

        private void btnreflesh_Click(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            webBrowser1.GoSearch();
        }

    }
}

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace İphoneİpaDownloadManager
{
    public partial class frmadres : Form
    {
        public frmadres()
        {
            InitializeComponent();
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            Close();
        }
        StreamWriter sw;
        private void btnekle_Click(object sender, EventArgs e)
        {
            sw = new StreamWriter(@"adresler.txt", true, Encoding.GetEncoding(1254));
            string eklenecekVeri = String.Format("{0}", txtAdres.Text);
            sw.WriteLine(eklenecekVeri);
            sw.Flush();
            txtAdres.Text = "";
            this.Close();
        }     
    }
}
 

 

Evet arkadaşlar örnek bir projenin  sonuna gelmiş olduk yeni  bir projede görüşmek üzere herkeze iyi calışmalar

 Saygılarımla Orhan Türk 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , İphone ,

C# Toplu Mail Gönderme Programı

9. January 2010

Evet Arkadaşlar sziler için bir yararlı  uygulama daha  hazırladım  bu  uygulamada c#  kullanarak  kullanıcılara toplu  mail gönderme işlemi yapan bir program  hazırladım   örnek programın

bitmiş hali  daha gelişmiş  versiyonu    yazıyorum   tabiki biter bitmez blog  da yayınlanmış  oluçaktır 

i




Source 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.IO;
using System.Net.Mail;
using System.Net;

namespace ExpTopluMailProject
{
    public partial class frmtoplumial : Form
    {
        public frmtoplumial()
        {
            InitializeComponent();
        }

        private void btnyukle_Click(object sender, EventArgs e)
        {
            try
            {
                opfileDialog.ShowDialog();
                if (opfileDialog.FileName != "")
                {
                    lblMail.Items.Clear();
                    StreamReader srRead = new StreamReader(opfileDialog.FileName);

                    while (srRead.EndOfStream == false)
                    {
                        lblMail.Items.Add(srRead.ReadLine().ToString());
                    }
                    srRead.Close();
                }
            }

            catch (Exception ex)
            {

                MessageBox.Show("Hatalı Yükleme !\n\n" + ex.Message);
            }
        }

        private void btngonder_Click(object sender, EventArgs e)
        {


            try
            {
                SmtpClient MailSender = new SmtpClient(txtmailSunucusu.Text);
                MailSender.Credentials = new NetworkCredential(txtmailAdresi.Text, txtsifre.Text);
                MailMessage Mail = new MailMessage();
                Mail.Body = txtIcerik.Text; // Mesajınız
                Mail.IsBodyHtml = true; // Mail Formatı // Eğer Mailiniz Html Kodu içermeyecekse False olsun
                Mail.Subject = txtkonu.Text; // Mailinizin Konusu
                Mail.From = new MailAddress(txtmailAdresi.Text); // Gönderen Adresi
                for (int i = 0; i < lblMail.Items.Count; i++) // Gönderilecek Maillerin Yüklenmesi.
                {
                    Mail.To.Add(lblMail.Items[i].ToString());
                }
                MailSender.Send(Mail); // Mailin Gönderilmesi
                Temizle();

                lblMail.Items.Clear();
                MessageBox.Show("Tüm Mailler Başarı İle Gönderildi");
                txtmailSunucusu.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hata Oluştu :\n\n" + ex.Message);
            }

        }
        //Tüm TextBox Temizle
        void Temizle()
        {
            txtmailSunucusu.Text = "";
            txtmailAdresi.Text = "";
            txtsifre.Text = "";
            txtIcerik.Text = "";
            txtkonu.Text = "";
        }
    }
}
 

Projenin  full    ExpTopluMailProject.rar (41,34 kb)

  Kaynak gelecekcoknet

Evet arkadaşlar örnek bir projein sonuna gelmiş olduk tekrar yeni bir projede görüşmek üzere herkeze iyi calışmalar 

Saygılarımla Orhan Türk 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , Tüm Projelerim

checkbox kullanarak liste öğeleri alın

7. January 2010

 

Merhaba arkadaşlar bu örnek projede console application  uygulamasında bir  windows projesi nasıl   calıştırılır onu  görelim

Örnek Proje

Console Application Code

 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace console_test
{

    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.CheckedListBox chkListPossibleValues;
        private System.Windows.Forms.ListBox lstSelected;
        private System.Windows.Forms.Button btnMove;
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            InitializeComponent();
            this.chkListPossibleValues.Items.Add("Ten");
          
        }

        private void InitializeComponent()
        {
            this.lstSelected = new System.Windows.Forms.ListBox();
            this.btnMove = new System.Windows.Forms.Button();
            this.chkListPossibleValues = new System.Windows.Forms.CheckedListBox();
            this.SuspendLayout();

            this.lstSelected.Location = new System.Drawing.Point(232, 8);
            this.lstSelected.Name = "lstSelected";
            this.lstSelected.Size = new System.Drawing.Size(136, 186);
            this.lstSelected.TabIndex = 1;

            this.btnMove.Location = new System.Drawing.Point(152, 80);
            this.btnMove.Name = "btnMove";
            this.btnMove.TabIndex = 3;
            this.btnMove.Text = "Move";
            this.btnMove.Click += new System.EventHandler(this.btnMove_Click);

            this.chkListPossibleValues.CheckOnClick = true;
            this.chkListPossibleValues.Items.AddRange(new object[] {"One", "Two", "Three",
                  "Four", "Five","Six","Seven", "Eight", "Nine"});
            this.chkListPossibleValues.Location = new System.Drawing.Point(8, 8);
            this.chkListPossibleValues.Name = "chkListPossibleValues";
            this.chkListPossibleValues.Size = new System.Drawing.Size(136, 184);
            this.chkListPossibleValues.TabIndex = 0;

            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(376, 205);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {this.btnMove,
                                  this.lstSelected,  this.chkListPossibleValues});
            this.Name = "Form1";
            this.Text = "List Boxes";
            this.ResumeLayout(false);


 
        }

        static void Main()
        {
            Application.Run(new Form1());
            Console.WriteLine("Form  Devrede Dışı  ");
            Console.ReadLine();
        }

        private void btnMove_Click(object sender, System.EventArgs e)
        {
            if (this.chkListPossibleValues.CheckedItems.Count > 0)
            {
                this.lstSelected.Items.Clear();
                foreach (string item in this.chkListPossibleValues.CheckedItems)
                {
                    this.lstSelected.Items.Add(item.ToString());
                }
                for (int i = 0; i < this.chkListPossibleValues.Items.Count; i++)
                {
                    this.chkListPossibleValues.SetItemChecked(i, false);
                }
            }
        }
    }
}

  Kaynak Web Sitw : Java2s

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , Console Application

C# İle Mobile Programlama

5. January 2010

Evet arkadaşlar sizler için bügün   birde Mobile Application  hazırladm  sadece başlangiç amaçlı bir örnek  yaptım 

 sizlerde visual studio nimetlerin den yararlanarak  böyle   başlıca projeler yaza bilirsiniz

Tabiki Unutmadan Microsoft Download Sayfasından Windows Mobile 6 Professional SDK Refresh indirmeyi unutmayalım   buda bir  bildiri.

 

 


Source Code :

using System;
using System.Windows.Forms;

namespace FirstMyDeviceProject
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

        }
        int _sayi1, _sayi2;
        double _sonuc;
        private void btnToplam_Click(object sender, EventArgs e)
        {
            if (chkTopla.Checked)
            {
                _sayi1 = Convert.ToInt32(txtsayi1.Text);
                _sayi2 = Convert.ToInt32(txtsayi2.Text);
                _sonuc = _sayi1 + _sayi2;
                lblSonuc.Text = _sonuc.ToString();
                Temiz();
            }
            else if (chkCarp.Checked)
            {
                _sayi1 = Convert.ToInt32(txtsayi1.Text);
                _sayi2 = Convert.ToInt32(txtsayi2.Text);
                _sonuc = _sayi1 * _sayi2;
                lblSonuc.Text = _sonuc.ToString();

                Temiz();
            }
            else if (chkcikart.Checked)
            {
                _sayi1 = Convert.ToInt32(txtsayi1.Text);
                _sayi2 = Convert.ToInt32(txtsayi2.Text);
                _sonuc = _sayi1 - _sayi2;
                lblSonuc.Text = _sonuc.ToString();
                Temiz();
            }
            else if (chkbol.Checked)
            {
                _sayi1 = Convert.ToInt32(txtsayi1.Text);
                _sayi2 = Convert.ToInt32(txtsayi2.Text);
                 _sonuc = _sayi1 / _sayi2;               

                  lblSonuc.Text = _sonuc.ToString();
                Temiz();
            }

        }

        void  Temiz()
        {
            txtsayi1.Text = "";
            txtsayi2.Text = "";
            txtsayi1.Focus();
        }
      
    }
}

Projenin Solution Kodu indir

Evet arkadaşlar örnek bir projenin sona gelmiş olduk  herkeze  iyi calışmalar kibk  

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , Windows Mobile

SQLile / SQL Tutorials( SQLile SQL Kullanımı /

4. January 2010

Merhaba Arkadşlar  sizlere bu örnek makkalede  Sqlite kullanımı  hakkında bilgiler  sunacağım işallah sizler için yararlı bir bilgi  kaynağı  olur diyorum 

Giriş

Bu eğitimde Sadece  Windows ve Linux için de geçerlidir.

Cmd.exe ilgili bazı bilgiler: http://www.ss64.com/nt/cmd.html,

http://www.linuxdevcenter.com/pub/ct/19 de bir dizi örnek tabloların içeriğini  nasıl kullanılır  görebilirsiniz .

 

SQLite yükleme

   
1. Http://www.sqlite.org/download.html git
   
2. Bir komut indirin yeni versiyonu satırı programı erişim ve SQLite veritabanları değiştirme. (örneğin, sqlite-3_2_7.zip. bu yazının sürümü için önemli değildir).
   
3. Bir dizin oluşturun (örneğin C: / SQLite3 "> c: \ SQLite3) ve unzip sqlite *. exe o dizindeki.

SQLite ile Kullanımı
Komut satırı yorumlayıcısı (Cmd.exe) Başlangıç:

 















C: \ WINNT \ system32>

Aşağıdaki komutu  oluşturun :

C: \ WINNT \ system32> cd c: \ SQLite3

 
ve "" girin.


Creation  / Açılış Veritabanı

Bir veri tabanı aşağıdaki komut ile  açılabilir:

C: \ SQLite3> SQLite3 mycds.sl3

sl2 kullanmak ve "SL3" SQLite sürüm 2 ve 3 için sırasıyla. bir dosya  ve programı yeniden  bir veritabanı içinde oluşturur.

C: \ SQLite3> SQLite3 mycds.sl3

SQLite version 3.2.7

"Girin." Talimatları için yardım

SQLite>

SQLite komutları

 "sqlit değiştirildi Not>". Bu programı SQL komutlarını çalıştırmaya hazır olduğunu gösteririr


Closing Veritabanı

"Type ".exit" or ".quit"  "." Programına çıkmak için çıkın:

sqlite>. çıkmak


Table Creation / Tablo Oluşturma

 
Şimdi iki alan içeren bir tablo oluşturalım.

sqlite>create table Artists (
--->ArtistID INTEGER PRIMARY KEY,
--->ArtistName TEXT)


 
unutmayın. Aşağıdaki tablo daha karmaşık bir örnektir.

sqlite>create table CDs (
--->CDID INTEGER PRIMARY KEY,
--->ArtistID INTEGER NOT NULL,
--->Title TEXT NOT NULL,
--->Date TEXT);


Table Population

Bu PRIMARY KEY AUTOINCREMENT varsayılan olduğunu unutmayın.

sqlite>insert into Artists (ArtistID,ArtistName) values (NULL,'Peter Gabriel');
sqlite>insert into Artists (ArtistID,ArtistName) values (NULL,'Bruce Hornsby');
sqlite>insert into Artists (ArtistID,ArtistName) values (NULL,'Lyle Lovett');
sqlite>insert into Artists (ArtistID,ArtistName) values (NULL,'Beach Boys');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,1,'So','1984');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,1,'Us','1992');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,2,'The Way It Is','1986');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,2,'Scenes from the Southside','1990');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,1,'Security','1990');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,3,'Joshua Judges Ruth','1992');
sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,4,'Pet Sounds','1966');


SQLite, ancak METİN veri (Tarih) değerleri  için  sadece   tek tırnak  kullanılır.

İpucu 1: Bir satır kopyalanabilir ve sağ CMD tıklayarak yapıştırılır. CMD Seçilen metni Shift sağ tıklayın (ya da" sağ tıklayın ve.

İpucu 2: Alternatif olarak, (adını ins_artists.sql gibi) aşağıdaki gibi  bir metin dosyası oluşturabilirsiniz:

-- insert 4 records into Artists (a comment line starts with "--") 
insert into Artists (ArtistID,ArtistName) values (NULL,'Peter Gabriel');
insert into Artists (ArtistID,ArtistName) values (NULL,'Bruce Hornsby');
insert into Artists (ArtistID,ArtistName) values (NULL,'Lyle Lovett');
insert into Artists (ArtistID,ArtistName) values (NULL,'Beach Boys');

nokta sonunda noktalı virgül (olmadan) komut çalıştırmak isterseniz :

sqlite>.read ins_artists.sql 

 

SELECT deyimi

ifadeleri   kontrol edelim .

sqlite>select * from Artists;   


and

sqlite>select * from CDs;    

Eğer diğer ,  alanın başlıklarını görüntülemek isterseniz , sqlite>. başlıkları şunlardır

 

ArtisID|ArtistName
1      |Peter Gabriel
2      |Bruce Hornsby
3      |Lyle Lovett
4      |Beach Boys

 

 and

CDID|ArtisID|Title                    |Date
1   |1      |So                       |1984
2   |1      |Us                       |1992
3   |2      |The Way It Is            |1986
4   |2      |Scenes from the Southside|1990
5   |1      |Security                 |1990
6   |3      |Joshua Judges Ruth       |1992
7   |4      |Pet Sounds               |1966
Diğer ifadeler :
sqlite>SELECT Title AS AlbumName FROM CDs;     
sqlite>SELECT Title FROM CDs WHERE Date>=1990 ORDER BY Title;     
sqlite>SELECT Date FROM CDs;     
sqlite>SELECT DISTINCT Date FROM CDs;     
sqlite>SELECT Title FROM CDs GROUP BY ArtistID;     
Iki  tablo arası   veri seçimi

Aşağıdaki SQL deyimi
sqlite>SELECT t1.ArtistName,CDs.Title FROM Artists t1, CDs WHERE t1.ArtistID=CDs.ArtistID    

gives

ArtistName   |Title
Peter Gabriel|So
Peter Gabriel|Us
Peter Gabriel|Security
Bruce Hornsby|The Way It Is
Bruce Hornsby|Scenes from the Southside
Lyle Lovett  |Joshua Judge Ruth
Beach Boys   |Pet Sounds
Bazı Sanatçılar için bir takma ad olarak kullanılan T1 yukarıdaki açıklamada. 

UPDATE deyimi

yanlış bir kayıt  durumun da 

sqlite>insert into Artists (ArtistID,ArtistName) values (NULL,'Supernatural');

Then correct:

sqlite>UPDATE Artists SET ArtistName ='Santana' WHERE ArtistID=5;     

Now you can insert a CD:

sqlite>insert into CDs (CDID,ArtistID,Title,Date) values (NULL,5,'Supernatural','1999');     

 

table silme komutu ,  deneme

 

sqlite>select * FROM CDs WHERE Title LIKE 'Super%';     

OK? Now we are sure what we are going to delete:

sqlite>DELETE FROM CDs WHERE Title LIKE 'Super%';     

As a precaution you can try first

sqlite>Select * From CDs WHERE Title LIKE 'Super%';     

Kaynak Adres  :  http://shokhirev.com/nikolai/abc/sql/sql.html

Saygılarımla Orhan Türk 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , SQL SERVER, Sqlite

C# Hard Disk Watcher

3. January 2010

Merhaba Arkadaşlar hiç merak etmiş oldunuz ,  mu biz  bilgisayar da  tüm işleri  yapıyoruz    ve  disk üzerinde  bu  işlemi yaparken  benim harddisk   neler yapıyor diyorsanız  tam size  göre bir c# projesi sunuyorum

 Download

Evet arkadaşlar bir örnek  program sunumu daha  yapmış olduk  net dünyasın'daki yenilikleri sizlere burada paylaşmaya devam edicem kibk  herkeze iyi calışmalar

Saygılarımla Orhan Türk 

Burada Bu Program Yazan  : Mohammad Mir mostafa  emegine sağlık diyorum  

 http://cid-f95da4761845205e.profile.live.com/

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C#

C++ And C# Sockets – Webserver refactored

3. January 2010

C++ Source Code

 

#include "Socket.h"
#include "HTTPAnswer.h"
 
using namespace std;
// Object files needs to link against Winsock2 Lib
#pragma comment(lib, "ws2_32.lib")
#define BUFFER_LENGTH 512 // Length of the recieve buffer - i needed to set it because sizeof(pointer) does always return 4 --> See recieve part
 
///// MAIN /////////////////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
 
    // check parameters
    if(argc < 2 || (string)argv[1] != "-p") {
        cout << "Start Server with -p PORT\n";
        return -1;
    }
 
    #ifdef _WIN32
        // the path of the executable of this programm is passed as default parameter
        string spfad = argv[0]; // as first default param
        // But the name of the Programm is in the path ( c:\path\to\programm\programm.exe )
        spfad = spfad.substr(0,spfad.find_last_of("\\")); // this deletes everything behind the last backslash
    #else
        // for linux its working as follows
        char pathbuffer[PATH_MAX];
        readlink("/proc/self/exe", pathbuffer, PATH_MAX);
        string spfad = pathbuffer;
        spfad = spfad.substr(0,spfad.find_last_of("/")); // this deletes everything behind the last slash
    #endif
    // this path is needed later on to load html files and so on!
 
    int            readableSockets,bufferLength=0;
    vector<int>    readableSocketsList;
    char*        buffer;
    Socket*        socket;
    HTTPAnswer    answer;
 
    // create a new socket
    try {
        socket = new Socket();
        socket->setNonBlocking(true);
        socket->bindToPort(atoi(argv[2]));
    } catch(char* error) {
        cout << error << endl;
        return -1; // exit programm
    }
 
    while(true) { // server loop
        cout << "Waiting for connections\n";
        try {
            readableSockets = socket->getReadableDescriptors(&readableSocketsList); // get the sockets which are readable now
        } catch(char* e) {
            cout << e << endl;
            break; // terminate server
        }
        cout << readableSockets << " readable sockets found...\n";
        for(unsigned int i=0;i<readableSocketsList.size();i++) { // loop trough all readable sockets and process them
            cout << "processing socket" << readableSocketsList[i] << endl;
            if(readableSocketsList[i] == socket->getDescriptorNumber())
                socket->acceptConnections(); // readable socket is main socket - this means that someone is trying to connect
            else {
                // read data and send back response
                string sbuffer;
                bool boolContinue = true;
 
                do { // recieve until there is nothing left
                    buffer = new char[BUFFER_LENGTH];
                    memset(buffer,0,sizeof(buffer));
                    try {
                        int newBufferLength=socket->receiveData(readableSocketsList[i],buffer,BUFFER_LENGTH); // this is where sizeof(buffer) does not work (at least on ubuntu)
                        if (newBufferLength == -1) {
                            delete [] buffer;
                            break; // everything has been recieved. stop
                        }
 
                        bufferLength+=newBufferLength;
                        sbuffer.append(buffer,0,newBufferLength);
 
                        if(newBufferLength < BUFFER_LENGTH) // everything is recieved now (needed under ubuntu or it will recieve forever)
                            boolContinue = false;
                    } catch(char* e) {
                        cout << e << endl;
                        boolContinue = false;
                    }
 
                    delete [] buffer;
 
                } while(boolContinue);
 
                if(bufferLength > 0) {
                    // now analyse recieved data
                    if(sbuffer.substr(0,3) != "GET") {
                        answer.status=500;
                        answer.filename="/500.html";
                    } else {
                        answer.filename="/www"+sbuffer.substr(4,sbuffer.find_first_of(" ",4)-4); // this extracts the path to the file
                    }
 
                    try {
                        socket->sendData(readableSocketsList[i],answer.HTTPResponse(spfad)); // send data back to client
                    } catch(char* e) {
                        cout << e << endl;
                    }
                }
 
                socket->closeSocket(readableSocketsList[i]); // close connection
            }
        }
    }
    cout << "Shutting down server..." << endl;
    socket->closeSocket();
    delete socket;
}

C# Source Code 

using System;
6     
7    public class Globals
8    {
9        ///<summary>
10        /// Object files needs to link against Winsock2 Lib
11        ////// MAIN /////////////////////////////////////////////////////////////////
12        ///Rule R189: 'main' changed into 'Main'
13        ///</summary>
14        public static int Main(string[] argv)
15        {
16            cout << "Start Server with -p PORT\n";
17            return -1;
18            // the path of the executable of this programm is passed as default parameter
19            // as first default param
20            // But the name of the Programm is in the path ( c:\path\to\programm\programm.exe )
21            // this deletes everything behind the last backslash
22            spfad = spfad.substr(0,spfad.find_last_of("\\"));
23            // this path is needed later on to load html files and so on!
24            int readableSockets ,bufferLength = 0;
25            string buffer;
26            Socket * socket;
27            try {
28                socket.setNonBlocking(true);
29                socket.bindToPort(atoi(argv[2]));
30            }
31            catch(string  error){
32                cout << error << endl;
33                // exit programm
34                return -1;
35            }
36     
37     
38            while(true){
39                cout << "Waiting for connections\n";
40                try {
41                    // get the sockets which are readable now
42                    readableSockets = socket.getReadableDescriptors(readableSocketsList);
43                }
44                catch(string  e){
45                    cout << e << endl;
46                    // terminate server
47                    break;
48                }
49     
50     
51                cout << readableSockets << " readable sockets found...\n";
52                for(// loop trough all readable sockets and process them
53                uint i = 0;
54                i < readableSocketsList.size();(i)++)
55                {
56                    cout << "processing socket" << readableSocketsList[i ] << endl;
57                    if(readableSocketsList[i ] == socket.getDescriptorNumber())
58                    {
59                        // readable socket is main socket - this means that someone is trying to connect
60                        socket.acceptConnections();
61                    }
62                    else
63                    {
64                        // read data and send back response
65                        bool boolContinue = true;
66                        do{
67                            buffer = new char();
68                            memset(buffer ,0,4);
69                            try {
70                                // this is where sizeof(buffer) does not work (at least on ubuntu)
71                                int newBufferLength = socket.receiveData(readableSocketsList[i ],buffer ,BUFFER_LENGTH);
72                                if(newBufferLength == -1)
73                                {
74                                    buffer = null;
75                                    // everything has been recieved. stop
76                                    break;
77                                }
78                                bufferLength += newBufferLength;
79                                sbuffer.append(buffer ,0,newBufferLength);
80                                // everything is recieved now (needed under ubuntu or it will recieve forever)
81                                if(newBufferLength < BUFFER_LENGTH)
82                                {
83                                    boolContinue = false;
84                                }
85                            }
86                            catch(string  e){
87                                cout << e << endl;
88                                boolContinue = false;
89                            }
90     
91     
92                            buffer = null;
93                        }
94                        while(boolContinue);
95                        if(bufferLength > 0)
96                        {
97                            // now analyse recieved data
98                            if(sbuffer.substr(0,3) != "GET")
99                            {
100                                answer.status = 500;
101                                answer.filename = "/500.html";
102                            }
103                            else
104                            {
105                                // this extracts the path to the file
106                                answer.filename = "/www" + sbuffer.substr(4,sbuffer.find_first_of(" ",4) - 4);
107                            }
108                            try {
109                                // send data back to client
110                                socket.sendData(readableSocketsList[i ],answer.HTTPResponse());
111                            }
112                            catch(string  e){
113                                cout << e << endl;
114                            }
115     
116     
117                        }
118                        // close connection
119                        socket.closeSocket(readableSocketsList[i ]);
120                    }
121                }
122            }
123            ;
124            cout << "Shutting down server..." << endl;
125            socket.closeSocket();
126            socket = null;
127            //return value: Added during conversion from C++
128            return 0;
129        }
130    }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , C++