C# Soket Programlama(C # Socket Programming)

6. April 2010

Read this article in your language IT | EN | DE | ES

Evet arkadaşlar bu örnek makkalemde sizlere c#  üzerinde örnek bir basit  socket programlama  sunumu  hazırladım

bunla beraber kaynak kodlarıda  indirip daha  detaylı inceliyebilirsiniz  şimdiden iyi calışmalar kolay gelsin

 

-------------------------------> Client Tarafındaki örnek kodumuz 

 

using System;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using SocketClient.Properties;

namespace SocketClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        TcpClient _client;
        NetworkStream _ns;
        StreamWriter _yazici;
        StreamReader _okuyucu;

        private void Button2Click(object sender, EventArgs e)
        {
            try
            {
                _client = new TcpClient(txtServer.Text, 7000);
            }
            catch (SocketException ex)
            {
                MessageBox.Show(Resources.Form1_Button2Click_Hata___ + ex.Message);
                return;
            }
            _ns = _client.GetStream();
            _okuyucu = new StreamReader(_ns);
            _yazici = new StreamWriter(_ns);
        }

        private void Button1Click(object sender, EventArgs e)
        {
            _yazici.WriteLine(txtMesaj.Text);
            _yazici.Flush();
            string serverCevap = _okuyucu.ReadLine();

            listBox1.Items.Add("Client Says:");
            listBox1.Items.Add(txtMesaj.Text);
            listBox1.Items.Add("Server Says:");
            listBox1.Items.Add(serverCevap);

            txtMesaj.Clear();
        }
    }
}

--------> Server Tarafındaki Örnek kodumuz

 using System;
using System.Net.Sockets;
using System.IO;

namespace SocketServer
{
    class Program
    {
        static void Main()
        {
            StreamReader okuyucu;
            StreamWriter yazici;

#pragma warning disable 612,618
            var dinleyici = new TcpListener(7000);
#pragma warning restore 612,618
            dinleyici.Start();

            Console.WriteLine("Sunucu Aktif...");
            TcpClient client = dinleyici.AcceptTcpClient();
            if (client.Connected)
            {
                Console.WriteLine("Client bağlandı...");
                NetworkStream ns = client.GetStream();
                okuyucu = new StreamReader(ns);
                yazici = new StreamWriter(ns);

                while (true)
                {
                    Console.WriteLine("Client mesajı : {0}", okuyucu.ReadLine());
                    yazici.WriteLine("Mesaj Server a ulaştı...");
                    yazici.Flush();
                }
            }
        }
    }
}
 


Source Code Download

Saygılarımla Orhan Türk
FacebookDigg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

C# ,

Comments

4/7/2010 3:46:19 PM #
Really great idea!
4/7/2010 5:13:57 PM #
In the meantime I thank you if you want to support me introduce my website if you need to be happy when people support the necessary resources to make something beautiful for me
4/7/2010 6:01:13 PM #
keep your good post I bookmarked your blog.
How about <a href="http://mp3in1.com"> search and download music mp3</a> ?
check this out http://mp3in1.com
4/9/2010 12:04:26 AM #
Great bog post! I really like your blog, and am a regular reader. Keep it up.
4/9/2010 1:45:33 AM #
Great post! I like your blog, and am a regular reader. I will be back soon!
4/10/2010 9:37:30 AM #
I was on that community forum and 1 fellow was discussing involving your web page. My interest brought me on this website. I do not have a single thing harmful to say concerning your blog, Sincere I believe this really is an incredible blog! Keep writing!
Selam
Selam
4/10/2010 2:12:43 PM #
Kaynak Kodu Linki Kırık yenilerseniz Sevinirim
4/12/2010 4:17:54 PM #
I was on this online community and 1 fellow was talking involving your website. My interest brought me here. I do not have anything harmful to express regarding your website, Sincere I'm sure this is an excellent web site! Keep writing!
4/13/2010 1:47:41 PM #
8) Hey you have provided us a magnificent post that could really assist us. I congratulate for your work.
4/18/2010 10:05:57 PM #
Wonderful information, thanks to the article writer. Its comprehensible to me now, the usefulness and value is overpowering. Many thanks once more and good luck!
sss
sss
4/20/2010 6:44:57 AM #
ya amınakodumun oğlu çalmışsın sharpnedir.com'dan
sss
sss
4/20/2010 6:45:04 AM #
ya amınakodumun oğlu çalmışsın sharpnedir.com'dan
4/21/2010 11:52:18 AM #
castiga bani - Win some money
5/7/2010 5:25:55 AM #
c# c# c# Do you agree to guest posts? I would like to write pair posts here.
5/14/2010 9:30:43 PM #
Kudos for doing this article. It is enjoyable reading.
5/17/2010 12:22:08 AM #
I do not have a single thing harmful to say concerning your blog, Sincere I believe this really is an incredible blog! Keep writing!
5/22/2010 1:33:03 AM #
I just couldnt leave your website before saying that I really enjoyed the quality information you offer to your visitors... Will be back often to check up on new stuff you post!
6/3/2010 4:06:12 PM #
well, anybody who has been seriously engaged is scientific work of any kind realizes that over the entrance to the gates of the temple of science are written the words: 'Ye must have faith.' Brianna
6/4/2010 8:59:24 PM #
This is a very good posting, I discovered your web page searching aol for a similar subject and came to this. I couldnt get to much additional info on this article, so it was wonderful to find this one. I will probably be returning to look at some other articles that you have another time.
6/5/2010 4:11:22 AM #
I think this is really helpful for C++ programmer. I am very much interested about C++. It is important for the acquire information about client.
6/6/2010 11:26:49 AM #
Intimately, the post is really the freshest on this laudable topic. I agree with your conclusions and will eagerly look forward to your incoming updates. Just saying thanks will not just be enough, for the phenomenal clarity in your writing. I will immediately grab your rss feed to stay abreast of any updates. Genuine work and much success in your business endeavors!
9/4/2010 4:40:26 PM #
Happy to have found this site.
9/5/2010 12:11:09 AM #
Impressive affair! THANK YOU!
9/5/2010 1:30:12 AM #
Greetings, You might want to know that this particular page is not displaying properly on the Samsung Slider. Anyway, I’m now browsing this article on my pc, Thanks
9/5/2010 3:27:40 AM #
Can I clone your article to my blog? Thank you.
9/5/2010 4:43:48 PM #
Thanks for posting this. I really appreciate it.

Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading



Sayfa 0.015625 saniyede yuklendi.