Merhaba,
Port dinlemek için c# da program yapmaya çalışıyorum fakat bazı satırlarda hata alıyorum. C# kodlama bilen nerde yanlışım olduğu hakkında yardımcı olabilir mi ? Programlama editörü olarak Windows Visual Studio 2010 kullanıyorum. 101 ve 131. line de Expected class,delegate,enum, interface, or struct hata açıklaması budur.
Kodlar
using System;
using System.Net.Sockets;
using System.IO ;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
//Burda server da tanımladıklarımızdan farklı olarak TcpClient sınıfı ile serverdan gelen bilgileri alıyoruz
public TcpClient Istemci;
private NetworkStream AgAkimi;
private StreamReader AkimOkuyucu;
private StreamWriter AkimYazici;
private System.Windows.Forms.Button buton;
private System.Windows.Forms.TextBox textbox;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override **** Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private **** InitializeComponent()
{
//Bu satırları Visual C# oluşturdu.
this.buton = new System.Windows.Forms.Button();
this.textbox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.buton.******** = new System.Drawing.Point(8, 40);
this.buton.Name = "buton";
this.buton.Size = new System.Drawing.Size(248, 23);
this.buton.TabIndex = 0;
this.buton.Text = "Sunucuya Baglan";
this.buton.Click += new System.EventHandler(this.buton_Click);
this.textbox.******** = new System.Drawing.Point(8, 8);
this.textbox.Name = "textbox";
this.textbox.Size = new System.Drawing.Size(248, 20);
this.textbox.TabIndex = 1;
this.textbox.Text = "Buraya Sunucuya göndereceginiz yaziyi yazin";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(264, 69);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textbox,
this.buton});
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "C#nedir?com";
this.Closing += new System.ComponentModel.CancelEventHandler(this.form1_kapatma);
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
//giriş noktamız olan mainde yeni bir form1 nesnesini çalıştırıyoruz
static **** Main()
{
Application.Run(new Form1());
}
//From1 yüklendiğinde TcpClient nesnesi oluşturup AgAkımından(NetworkStream) verileri okuyoruz
private **** Form1_Load(object sender, System.EventArgs e)
{
try
{
Istemci = new TcpClient("localhost", 1234);
}
catch
{
Console.WriteLine("Baglanamadi");
return;
}
//Server programında yaptıklarımızı burda da yapıyoruz.
AgAkimi = Istemci.GetStream();
AkimOkuyucu = new StreamReader(AgAkimi);
AkimYazici = new StreamWriter(AgAkimi);
}
}
private **** buton_Click(object sender, System.EventArgs e)
{
//Kullanıcı butona her tıkladığında textbox'ta yazı yoksa uyarı veriyoruz
//Sonra AkimYazici vasıtası ile AgAkımına veriyi gönderip sunucudan gelen
//cevabı AkimOkuyucu ile alıp Mesaj la kullanıcıya gösteriyoruz
//Tabi olası hatalara karşı, Sunucuya bağlanmada hata oluştu mesajı veriyoruz.
try
{
if (textbox.Text=="")
{
MessageBox.Show("Lütfen bir yazi giriniz","Uyari");
textbox.Focus();
return ;
}
string yazi;
AkimYazici.WriteLine(textbox.Text);
AkimYazici.Flush();
yazi = AkimOkuyucu.ReadLine();
MessageBox.Show(yazi,"Sunucudan Mesaj var");
}
catch
{
MessageBox.Show("Sunucuya baglanmada hata oldu...");
}
}
//TVe bütün oluşturduğumuz nesneleri form kapatıldığında kapatıyoruz.
public **** form1_kapatma(object o , CancelEventArgs ec)
{
try
{
AkimYazici.Close();
AkimOkuyucu.Close();
AgAkimi.Close();
}
catch
{
MessageBox.Show("Düzgün kapatilamiyor");
}
}
Port dinlemek için c# da program yapmaya çalışıyorum fakat bazı satırlarda hata alıyorum. C# kodlama bilen nerde yanlışım olduğu hakkında yardımcı olabilir mi ? Programlama editörü olarak Windows Visual Studio 2010 kullanıyorum. 101 ve 131. line de Expected class,delegate,enum, interface, or struct hata açıklaması budur.
Kodlar
using System;
using System.Net.Sockets;
using System.IO ;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
//Burda server da tanımladıklarımızdan farklı olarak TcpClient sınıfı ile serverdan gelen bilgileri alıyoruz
public TcpClient Istemci;
private NetworkStream AgAkimi;
private StreamReader AkimOkuyucu;
private StreamWriter AkimYazici;
private System.Windows.Forms.Button buton;
private System.Windows.Forms.TextBox textbox;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override **** Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private **** InitializeComponent()
{
//Bu satırları Visual C# oluşturdu.
this.buton = new System.Windows.Forms.Button();
this.textbox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.buton.******** = new System.Drawing.Point(8, 40);
this.buton.Name = "buton";
this.buton.Size = new System.Drawing.Size(248, 23);
this.buton.TabIndex = 0;
this.buton.Text = "Sunucuya Baglan";
this.buton.Click += new System.EventHandler(this.buton_Click);
this.textbox.******** = new System.Drawing.Point(8, 8);
this.textbox.Name = "textbox";
this.textbox.Size = new System.Drawing.Size(248, 20);
this.textbox.TabIndex = 1;
this.textbox.Text = "Buraya Sunucuya göndereceginiz yaziyi yazin";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(264, 69);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textbox,
this.buton});
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "C#nedir?com";
this.Closing += new System.ComponentModel.CancelEventHandler(this.form1_kapatma);
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
//giriş noktamız olan mainde yeni bir form1 nesnesini çalıştırıyoruz
static **** Main()
{
Application.Run(new Form1());
}
//From1 yüklendiğinde TcpClient nesnesi oluşturup AgAkımından(NetworkStream) verileri okuyoruz
private **** Form1_Load(object sender, System.EventArgs e)
{
try
{
Istemci = new TcpClient("localhost", 1234);
}
catch
{
Console.WriteLine("Baglanamadi");
return;
}
//Server programında yaptıklarımızı burda da yapıyoruz.
AgAkimi = Istemci.GetStream();
AkimOkuyucu = new StreamReader(AgAkimi);
AkimYazici = new StreamWriter(AgAkimi);
}
}
private **** buton_Click(object sender, System.EventArgs e)
{
//Kullanıcı butona her tıkladığında textbox'ta yazı yoksa uyarı veriyoruz
//Sonra AkimYazici vasıtası ile AgAkımına veriyi gönderip sunucudan gelen
//cevabı AkimOkuyucu ile alıp Mesaj la kullanıcıya gösteriyoruz
//Tabi olası hatalara karşı, Sunucuya bağlanmada hata oluştu mesajı veriyoruz.
try
{
if (textbox.Text=="")
{
MessageBox.Show("Lütfen bir yazi giriniz","Uyari");
textbox.Focus();
return ;
}
string yazi;
AkimYazici.WriteLine(textbox.Text);
AkimYazici.Flush();
yazi = AkimOkuyucu.ReadLine();
MessageBox.Show(yazi,"Sunucudan Mesaj var");
}
catch
{
MessageBox.Show("Sunucuya baglanmada hata oldu...");
}
}
//TVe bütün oluşturduğumuz nesneleri form kapatıldığında kapatıyoruz.
public **** form1_kapatma(object o , CancelEventArgs ec)
{
try
{
AkimYazici.Close();
AkimOkuyucu.Close();
AgAkimi.Close();
}
catch
{
MessageBox.Show("Düzgün kapatilamiyor");
}
}
Son düzenleme: