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 DownloadSaygılarımla Orhan Türk
b21dc3ce-2355-4028-a9c4-d900f48443b0|0|.0
C#
c#, socket programlama