Job 7
Text And Voice Chat
Disusun oleh :
Kelompok 1
1. Desyana S.P. (3.34.12.0.07)
2. Dwi Achiyari B. P. (3.34.12.0.09)
3. Evan Enza R. (3.34.12.0.10)
4. Sukirno (3.34.12.0.20)
IK-2A
menunggu acknowledgement pada koneksi yang dibangun. Sebagai contohnya, RTT yang
didapat dari LAN biasanya hanya dalam besaran milisecond sementara untuk WAN, RTT
bisa dalam besaran second. TCP selalu menghitung RTT dari koneksi yang dibangun secara
terus – menerus, hal ini dikarenakan RTT banyak dipengaruhi oleh keadaan traffic jaringan
yang selalu berubah – ubah setiap waktu.
TCP dapat mengurutkan setiap byte data yang dikirim. Sebagai contohnya, asumsikan
suatu aplikasi mengirimkan 2048 bytes data ke TCP socket, yang menyebabkan TCP akan
mengirim sebanyak 2 segment. Segment yang pertama mengirimkan data dengan urutan 1 –
1024 dan segment yang kedua akan mengirimkan data dengan urutan 1025 – 2048. Apabila
segment yang diterima tidak sesuai dengan segment yang dikirim, maka TCP si penerima
akan meminta pengiriman ulang 2 segment tersebut berdasarkan urutan yang benar sebelum
dikirim ke level aplikasi si penerima. Apabila TCP menerima duplikasi data dari pengirim
( misal network memperkirakan ada segment data yang hilang, sehingga meminta
pengiriman ulang, padahal segment data tersebut tidak benar – benar hilang dikarenakan
network overload), maka TCP dapat mendeteksi duplikasi data tersebut dan membuang data
yang tidak digunakan.
Pada saat suatu aplikasi socket melakukan koneksi, kita dapat melihat state – state yang
dialami oleh aplikasi socket tersebut. State – state yang dilakukan oleh TCP pada saat
melakukan koneksi yaitu :
1. LISTEN
2. SYN-SENT
3. SYN-RECEIVED
4. ESTABLISHED
5. FIN-WAIT-1
6. FIN-WAIT-2
7. CLOSE-WAIT
8. CLOSING
9. LAST-ACK
10. TIME-WAIT
11. CLOSED
LISTEN
Konsep UDP
UDP ( User Datagram Protocol ) adalah transport layer yang tidak andal ( unreliable ),
connectionless dan merupakan kebalikan dari transport layer TCP. Dengan menggunakan
UDP, setiap aplikasi socket dapat mengirimkan paket – paket yang berupa datagram. Istilah
datagram diperuntukkan terhadap paket dengan koneksi yang tidak andal ( unreliable service
). Koneksi yang andal selalu memberikan keterangan apabila pengiriman data gagal,
sedangkan koneksi yang tidak andal tidak akan mengirimkan keterangan meski pengiriman
data gagal.
UDP tidak menjamin kevalidan data saat data sampai ke si penerima. Datagram yang
sampai mempunyai kemungkinan tidak sampai, rusak, duplikasi atau hilang tanpa diketahui
penyebabnya. Penggunaan UDP lebih tepat diperuntukkan untuk data – data kecil dengan
jumlah banyak. Dengan perilaku UDP yang tidak berusaha untuk mengecek apakah data
yang dikirim telah sampai atau tidak membuat UDP lebih cepat dan lebih efisien. Aplikasi –
aplikasi yang bersifat real time seringkali menggunakan UDP sebagai protokolnya, hal
tersebut dikarenakan paket yang hilang lebih bisa ditolerir daripada paket yang datang
terlambat ( contoh aplikasi realtime: Video Streaming ). Tidak seperti TCP, UDP juga
menyediakan jenis paket broadcast (mengirim paket ke local network) dan multicast
(mengirim paket ke semua subscriber).
Dalam UDP, client tidak membangun koneksi dengan server, melainkan client hanya
mengirim paket data ke server tanpa mengecek apakah server tersebut telah siap atau tidak.
Sama halnya dengan server tidak menerima koneksi dengan fungsi accept, namun server
hanya menjalankan perintah untuk menerima data, server akan terus menunggu sampai data
diterima.
4. Agar aplikasi chat tersebut dapat dijalankan, terlebih dahulu buat kode programnya.
5. Terlebih dahulu masukkan library dan buat variable sebagai berikut :
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Imports System
Imports System.Net.Dns
Imports System.Drawing.Bitmap
Imports CustomControls.IconComboBox
Imports UNOLibs.Net.ClientClass
Imports RapChatLib.RapChatLib
#Region "Declarations"
#End Region
#Region "Form"
Me.Location = My.Settings.WindowPosition
Me.Size = My.Settings.WindowSize
txtSound.Text = My.Settings.Audio
txtName.Text = My.Settings.Username
PicClient.ImageLocation = My.Settings.DisplayPic
picMypic.ImageLocation = My.Settings.DisplayPic
frmSettings.chkSound.CheckState = My.Settings.ChkSound
My.Settings.WindowPosition = Me.Location
My.Settings.WindowSize = Me.Size
My.Settings.Username = txtName.Text
My.Settings.DisplayPic = PicClient.ImageLocation
My.Settings.Audio = txtSound.Text
My.Settings.Save()
End If
End Sub
#End Region
#Region "Functions"
NotifyIcon1.BalloonTipText = Message
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
frmMessage.Show()
frmMessage.lblMessage.Text = Message
lblStat.Text = ("Last Message Received At " &
My.Computer.Clock.LocalTime)
End If
End If
End If
End Sub
btnSend.Enabled = True
Else
btnClear.Enabled = False
btnSend.Enabled = False
End If
End Sub
End Sub
bmp.Save(ms, Imaging.ImageFormat.Bmp)
abyt = ms.ToArray()
imgstr = System.Convert.ToBase64String(abyt)
TextBox1.Text = imgstr
PicClient.Image = picMypic.Image
Else
PicClient.ImageLocation = My.Application.Info.DirectoryPath &
"\Data\Users.png"
picMypic.ImageLocation = My.Application.Info.DirectoryPath &
"\Data\Users.png"
10 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
End If
End Sub
End Sub
11 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
If DialogResult.OK Then
RichTextBox1.Text += (txtName.Text & " Is Sending You a File...") +
vbCrLf
clnt.SendFiles(cmbAddress.Text, 65533, OpenFileDialog1.FileNames)
Else
Exit Sub
End If
End Sub
"\Sounds\Notify.wav")
End Sub
#End Region
#Region "Status"
btnSend.PerformClick()
pnlStatus.Visible = True
lblStatus.Text = "Your Status is currently set to Appear Offline"
End Sub
#End Region
PicMe.Image = Form1.PicClient.Image
x = Screen.GetWorkingArea(Me).Width
y = Screen.GetWorkingArea(Me).Height
Me.Location = New Point(x, y)
Timer1.Enabled = True
End Sub
15 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
Timer1.Enabled = False
Timer2.Enabled = True
Else
Me.Location = New Point(x, y)
y = y - 1
End If
End Sub
End Class
10. Buat form untuk new address dengan tampilan berikut :
11. Kemudian masukkan kode program sebagai berikut pada form tersebut :
16 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
Imports CustomControls.IconComboBox
End Class
Form1.picMypic.ImageLocation = picDisplay.ImageLocation
Form1.RichTextBox1.Font = New Font(cmbFont.Text, cmbSize.Text)
My.Settings.Save()
Me.Close()
End Sub
cmbFont.Text = Form1.RichTextBox1.Font.Name
cmbSize.Text = Form1.RichTextBox1.Font.Size
picDisplay.ImageLocation = Form1.PicClient.ImageLocation
txtPic.Text = Form1.PicClient.ImageLocation
End Sub
18 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
19 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
20 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
5. Jika IP sudah didapatkan pada aplikasi chat, silahkan hubungkan ke user lain dengan
memasukkan IP pada komputer lain :
21 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
VOICE CHAT
22 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
namespace VoiceChat
{
public partial class VoiceChat : Form
{
23 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
public VoiceChat()
{
InitializeComponent();
Initialize();
}
/*
* Initializes all the data members.
*/
private void Initialize()
{
try
{
device = new Device();
device.SetCooperativeLevel(this, CooperativeLevel.Normal);
24 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
bufferSize = captureBufferDescription.BufferBytes;
bIsCallActive = false;
nUdpClientFlag = 0;
25 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
/*
* Commands are received asynchronously. OnReceive is the handler for them.
*/
private void OnReceive(IAsyncResult ar)
{
try
{
EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);
26 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
{
//Start a call.
InitializeCall();
break;
}
case Command.Bye:
{
//Check if the Bye command has indeed come from the user/IP with which
we have
//a call established. This is used to prevent other users from sending
a Bye, which
//would otherwise end the call.
if (receivedFromEP.Equals (otherPartyEP) == true)
{
//End the call.
UninitializeCall();
}
break;
}
}
/*
* Send synchronously sends data captured from microphone across the network on port 1550.
*/
private void Send()
{
try
{
//The following lines get audio from microphone and then send them
//across network.
CreateNotifyPositions();
captureBuffer.Start(true);
//Choose the vocoder. And then send the data to other party at port 1550.
if (vocoder == Vocoder.ALaw)
{
byte[] dataToWrite = ALawEncoder.ALawEncode(memStream.GetBuffer());
udpClient.Send(dataToWrite, dataToWrite.Length,
otherPartyIP.Address.ToString (), 1550);
}
else if (vocoder == Vocoder.uLaw)
{
byte[] dataToWrite = MuLawEncoder.MuLawEncode(memStream.GetBuffer());
udpClient.Send(dataToWrite, dataToWrite.Length,
otherPartyIP.Address.ToString(), 1550);
}
else
{
byte[] dataToWrite = memStream.GetBuffer();
udpClient.Send(dataToWrite, dataToWrite.Length,
otherPartyIP.Address.ToString(), 1550);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "VoiceChat-Send ()", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
captureBuffer.Stop();
//When flag is two then it means we have got out of loops in Send and Receive.
while (nUdpClientFlag != 2)
{ }
/*
* Receive audio data coming on port 1550 and feed it to the speakers to be played.
*/
private void Receive()
{
try
{
bStop = false;
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
while (!bStop)
{
//Receive data.
byte[] byteData = udpClient.Receive(ref remoteEP);
28 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
notify.SetNotificationPositions(new BufferPositionNotify[]
{ bufferPositionNotify1, bufferPositionNotify2 });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "VoiceChat-CreateNotifyPositions ()",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
29 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
bIsCallActive = false;
btnCall.Enabled = true;
btnEndCall.Enabled = false;
}
/*
* Send a message to the remote party.
*/
private void SendMessage(Command cmd, EndPoint sendToEP)
{
try
{
//Create the message to send.
Data msgToSend = new Data();
30 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
{
MessageBox.Show(ex.Message, "VoiceChat-SendMessage ()", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
if (bIsCallActive)
{
UninitializeCall();
DropCall();
}
}
}
}
//Vocoder
enum Vocoder
{
ALaw, //A-Law vocoder.
uLaw, //u-Law vocoder.
None, //Don't use any vocoder.
}
//The data structure by which the server and the client interact with
//each other.
class Data
{
//Default constructor.
public Data()
{
this.cmdCommand = Command.Null;
this.strName = null;
vocoder = Vocoder.ALaw;
}
//This check makes sure that strName has been passed in the array of bytes.
if (nameLen > 0)
this.strName = Encoding.UTF8.GetString(data, 8, nameLen);
else
this.strName = null;
}
return result.ToArray();
}
public string strName; //Name by which the client logs into the room.
public Command cmdCommand; //Command type (login, logout, send message, etc).
public Vocoder vocoder;
}
}
Gambar di PC lain
32 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
V. Kesimpulan
Dari praktikum tentqng text dan voice chat yang telah dilakukan dapat disimpulkan bahwa
- Program voice chat digunakan dengan menggunakan konsep UDP dimana untuk dapat
terkoneksi antara PC satu dengan PC lain, setiap PC harus terhubung didalam suatu
jaringan. PC bisa menggunakan media kabel UTP, Adhoc, wifi ataupun media yang lain
yang dapat menginjinkan PC untu saling berbagi nomor IP,
- Untuk dapat menggunakan voice chat hal yang perlu dilakukan pertama adalah
memastikan apabila komputer terinstal minimal komponen directx 9 dan net framework
2.0, hal ini diperlukan agar library – library yang digunakan untuk melakukan voice chat
bisa digunakan dengan baik,
- Bahasa aras tinggi C# digunakan karena memiliki library yang lebih banyak
dibandingkan dengan bahasa aras ringgi vb, khususnya didalam koneksi jaringan,
33 | M i k r o p r o c e s s o r d a n A n t a r m u k a
Kelompok 1 Job 7- Text and voice chat
- Library – library yang digunakan untuk dapat berkomunikasi melalui jaringan adalah
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound; //menggunakan directx untuk dapat
melakukan komunikasi suara
using System.IO;
using System.Threading;
using System.Net.Sockets;
using System.Net;
using g711audio;
34 | M i k r o p r o c e s s o r d a n A n t a r m u k a