Aşağıdaki chat uygulamasının tek bilgisayarda gerçeklenebilmesi için 2 tane form açılmalıdır.Ip değerleri otomatik olarak gelmektedir bilgisayarın kullanmadığı herhangi iki portu seçip diğerinde de client1 kısmına yazılan port numarasını client2 ye ilkinde client2 de yazan port numarasını da client1 e yazarak send butonuna basılması sonucu bağlantı sağlanmış olacaktır.
ANA EKRAN
(Textbox isimleri ile birlikte)
Örnek Uygulama
C# Kodu
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.Net;
using System.Net.Sockets;
namespace chat
{
public partial class Form1 : Form
{
Socket sck;
EndPoint eplocal, epremote;
public Form1()
{
InitializeComponent();
sck = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
sck.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress,true);
textBox1.Text = GetLocalIP();
textBox3.Text = GetLocalIP();
}
private string GetLocalIP()
{
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily==AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
return "127.0.0.1";
}
private void MessageCallBack(IAsyncResult aResult)
{
try
{
int size = sck.EndReceiveFrom(aResult,ref epremote);
if (size>0)
{
byte[] receivedData = new byte[1464];
receivedData = (byte[])aResult.AsyncState;
ASCIIEncoding eEncoding = new ASCIIEncoding();
string recievedMessage = eEncoding.GetString(receivedData);
listBox1.Items.Add("Friend:"+recievedMessage);
}
byte []buffer = new byte [1500];
sck.BeginReceiveFrom(buffer,0,buffer.Length,SocketFlags.None,ref epremote, new AsyncCallback(MessageCallBack),buffer);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
System.Text.ASCIIEncoding enc= new System.Text.ASCIIEncoding();
byte[] msg = new byte [1500];
msg = enc.GetBytes(textBox5.Text);
sck.Send(msg);
listBox1.Items.Add("You:"+textBox5.Text);
textBox5.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
eplocal = new IPEndPoint(IPAddress.Parse(textBox1.Text),Convert.ToInt32(textBox2.Text));
sck.Bind(eplocal);
epremote = new IPEndPoint(IPAddress.Parse(textBox3.Text), Convert.ToInt32(textBox4.Text));
sck.Connect(epremote);
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epremote, new AsyncCallback(MessageCallBack), buffer);
button1.Text = "Connected";
button1.Enabled = false;
button2.Enabled = true;
textBox5.Focus();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString()); ;
}
}
}
}
TEN - The wire system for Teton's copper wires
YanıtlaSilTeton's copper wire is used in titanium trim reviews many forms as a conduit citizen titanium watch for mens titanium wedding rings the wire system for copper-type copper titanium band rings wires. The tesium is one of the world's omega seamaster titanium