1-) C# - socket programlama
Son olarak sıkça karşılaşılan Socket Exception'lardan 2sine göz atalım.
Eğer dinlemeye çalıştığınız portu dinleyen başka bir yazılım o bilgisayarda mevcut ise aşağıdaki hata ile karşılaşırsınız.
An attempt was made to access a socket in a way forbidden by its access permissions.
Erişim izinlerince izin verilmeyen bir şekilde bir yuvaya erişilmeye çalışıldı.
Eğer bilgisayarınızda bir virüs programı veya güvenlik duvarı port erişimlerini engelliyorsa aşağıdaki hatalar ile karşılaşırsınız:
TCP error code 10061: No connection could be made because the target machine actively refused it.
[System.Net.Sockets.SocketException] = {“Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı 127.0.0.1:5555”}
Umarım faydalı olmuştur.
hazırı var internette adresi aşşağıda multi client
http://www.gencklavyeler.com/forum/konu-c-c-sharp-chat-uygulamasi-online-chat-programi-17045.html
1-)Server.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace server
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
try
{
IPAddress IP = IPAddress.Parse("192.168.1.1");
System.Net.Sockets.TcpListener listener = new System.Net.Sockets.TcpListener(IP, 1010);
listener.Start();
Byte[] bytes = new Byte[1024];
String data = null;
while (true)
{
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Bağlantı Sağlandı...");
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
Console.WriteLine("Data alındı : {0}", data);
data = data.ToLower();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
Console.WriteLine("Data değiştirilip gönderildi : {0}", data);
stream.Write(msg, 0, msg.Length);
}
client.Close();
}
}
catch (SocketException ex)
{
Console.WriteLine("SocketException: {0}", ex.Message);
}
finally
{
Console.Read();
}
}
}
}
2-)Client.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
TcpClient client;
NetworkStream stream;
StreamReader streamReader;
StreamWriter streamWriter;
try
{
client = new TcpClient("192.168.1.1", 1010);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
//Server programında yaptıklarımızı burda da yapıyoruz.
stream = client.GetStream();
streamReader = new StreamReader(stream);
streamWriter = new StreamWriter(stream);
streamWriter.WriteLine("Client mesaj gönderdi.");
streamWriter.Flush();
string received = streamReader.ReadLine();
MessageBox.Show(received, "Server Mesaj Gönderdi.");
}
}
}