Aplikasi Chatting |
Aplikasi yang di buat khusus untuk berkomunikasi sesama teman, group, atau komunitas dalam suatu jaringan wireless/hotspot.
Daftar Komponen
Rincian Codding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace Chatting
{
public partial class Form1 : Form
{
delegate void AddMessage(string message);
string nama_user;
int port = 11000;
string broadcast;
IPAddress alamat_broadcast = IPAddress.Broadcast;
UdpClient penerima_client = new UdpClient(11000);
UdpClient pengirim_client;
Thread jalur_penerima;
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
bt_kirim.Click += new EventHandler(bt_kirim_Click);
this.ActiveControl = tx_user;
rich_chat.ReadOnly = true;
tx_kirim.Enabled = false;
bt_selesai.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
ThreadStart mulai = new ThreadStart(penerima);
jalur_penerima = new Thread(mulai);
jalur_penerima.IsBackground = true;
jalur_penerima.Start();
}
private void aksi()
{
tx_kirim.Text = tx_kirim.Text.TrimEnd();
if (!string.IsNullOrEmpty(tx_kirim.Text))
{
if(nama_user != "")
{
string u_kirim = "<" + nama_user + "> :" + tx_kirim.Text;
byte[] data = Encoding.ASCII.GetBytes(u_kirim);
pengirim_client.Send(data, data.Length);
tx_kirim.Text = "";
}
else
{
string u_kirim = "<" + Environment.MachineName + "> :" + tx_kirim.Text;
byte[] data = Encoding.ASCII.GetBytes(u_kirim);
pengirim_client.Send(data, data.Length);
tx_kirim.Text = "";
}
}
}
private void bt_kirim_Click(object sender, EventArgs e)
{
aksi();
}
private void penerima()
{
IPEndPoint end_point = new IPEndPoint(IPAddress.Any, port);
AddMessage pesan_wakil = pesan_diterima;
while (true)
{
byte[] data = penerima_client.Receive(ref end_point);
string message = Encoding.ASCII.GetString(data);
Invoke(pesan_wakil, message);
System.Console.Beep(1500, 300);
}
}
private void pesan_diterima(string pesan)
{
rich_chat.Text += pesan + "\n";
}
private void bt_kirim_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
aksi();
}
}
private void bt_mulai_Click(object sender, EventArgs e)
{
nama_user = Convert.ToString(tx_user.Text);
broadcast = Convert.ToString(alamat_broadcast);
pengirim_client = new UdpClient(broadcast, port);
pengirim_client.EnableBroadcast = true;
tx_kirim.Enabled = true;
tx_user.Enabled = false;
bt_mulai.Enabled = false;
bt_kirim.Enabled = true;
bt_selesai.Enabled = true;
}
private void bt_selesai_Click(object sender, EventArgs e)
{
tx_user.Enabled = true;
tx_kirim.Enabled = false;
bt_kirim.Enabled = false;
bt_mulai.Enabled = true;
bt_selesai.Enabled = false;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace Chatting
{
public partial class Form1 : Form
{
delegate void AddMessage(string message);
string nama_user;
int port = 11000;
string broadcast;
IPAddress alamat_broadcast = IPAddress.Broadcast;
UdpClient penerima_client = new UdpClient(11000);
UdpClient pengirim_client;
Thread jalur_penerima;
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
bt_kirim.Click += new EventHandler(bt_kirim_Click);
this.ActiveControl = tx_user;
rich_chat.ReadOnly = true;
tx_kirim.Enabled = false;
bt_selesai.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
ThreadStart mulai = new ThreadStart(penerima);
jalur_penerima = new Thread(mulai);
jalur_penerima.IsBackground = true;
jalur_penerima.Start();
}
private void aksi()
{
tx_kirim.Text = tx_kirim.Text.TrimEnd();
if (!string.IsNullOrEmpty(tx_kirim.Text))
{
if(nama_user != "")
{
string u_kirim = "<" + nama_user + "> :" + tx_kirim.Text;
byte[] data = Encoding.ASCII.GetBytes(u_kirim);
pengirim_client.Send(data, data.Length);
tx_kirim.Text = "";
}
else
{
string u_kirim = "<" + Environment.MachineName + "> :" + tx_kirim.Text;
byte[] data = Encoding.ASCII.GetBytes(u_kirim);
pengirim_client.Send(data, data.Length);
tx_kirim.Text = "";
}
}
}
private void bt_kirim_Click(object sender, EventArgs e)
{
aksi();
}
private void penerima()
{
IPEndPoint end_point = new IPEndPoint(IPAddress.Any, port);
AddMessage pesan_wakil = pesan_diterima;
while (true)
{
byte[] data = penerima_client.Receive(ref end_point);
string message = Encoding.ASCII.GetString(data);
Invoke(pesan_wakil, message);
System.Console.Beep(1500, 300);
}
}
private void pesan_diterima(string pesan)
{
rich_chat.Text += pesan + "\n";
}
private void bt_kirim_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
aksi();
}
}
private void bt_mulai_Click(object sender, EventArgs e)
{
nama_user = Convert.ToString(tx_user.Text);
broadcast = Convert.ToString(alamat_broadcast);
pengirim_client = new UdpClient(broadcast, port);
pengirim_client.EnableBroadcast = true;
tx_kirim.Enabled = true;
tx_user.Enabled = false;
bt_mulai.Enabled = false;
bt_kirim.Enabled = true;
bt_selesai.Enabled = true;
}
private void bt_selesai_Click(object sender, EventArgs e)
{
tx_user.Enabled = true;
tx_kirim.Enabled = false;
bt_kirim.Enabled = false;
bt_mulai.Enabled = true;
bt_selesai.Enabled = false;
}
}
}
Hasil Apliasi Chatting |
Jika Anda kurang puas atau ingin menambahkan ide
Anda dapat mengkostumnya di Form/View code nya
Untuk keterangan lebih lanjut lihat slide
Download Slide
Download Program
2 komentar:
bro program nya sama slide nya ko tidak bisa di
download nya
gabisa didownload
Posting Komentar