Programming VB.NET : Aplikasi Chat Sederhana Network Programming Client/Server

Belajar VB.Net khusus pemula : membuat aplikasi chat sederhana Client/Server Tcpclient dan MultiThread vb.net tutorial, selengkapnya di sector code

Belajar pemrograman vb.net : membuat aplikasi Chat sederhana menggunakan bahasa pemrograman vb.net, dimana aplikasi chat antara client dan server serta dari server dan client menggunakan TCPclient dan Multi Thread bahasa pemrograman vb.net. Network programming aplikasi chat sederhana dengan client satu akan bisa mengirimkan data kepada server dalam sebuah jaringan yang sudah ditentukan ip Addres dan nomor Port nya. aplikasi jaringan sederhana ini dibuat menggunakan visual studio 2015.

langsung saja, silahkan buka aplikasi visual studio kamu, bisa juga menggunakan visual studio 2010 atau versi diatasnya. dalam aplikasi chat sederhana ini kita akan membuat 2 project baru dengan nama antara lain : "server" dan "client". kedua project tersebut akan dibahas secara mendetail.
Aplikasi Chat Sederhana Network Programming Client/Server

Project Server


Buatlah project baru dengan nama server dan desain tampilan form server kamu seperti gambar dibawah ini :
Server TCP
jika sudah selesai, mari kita buat Class baru pada project server kamu dan beri nama "CPcontrolClass.vb" . tuliskan seluruh code berikut kedalam Class CPcontrolClass.vb

Source Code  CPcontrolClass.vb Server Project

CPcontrolClassImports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading

Public Class TCPcontrolClass

    Public Event MessageReceived(sender As TCPcontrolClass, Data As String)

    'SERVER CONFIGURATIONS
    Public serverIP As IPAddress = IPAddress.Parse("127.0.0.1")
    Public serverPORT As Integer = 8080
    Public server As TcpListener

    Private comThread As Thread
    Public isListening As Boolean = True

    ' CLIENT CONFIGURATIONS
    Private client As TcpClient
    Private clientData As StreamReader

    Public Sub New()
        server = New TcpListener(serverIP, serverPORT)
        server.Start()
        comThread = New Thread(New ThreadStart(AddressOf Listening))
        comThread.Start()
    End Sub

    Private Sub Listening()
        'CREATE LISTENER LOOP
        Do Until isListening = False
            'ACCEPT INCOMING CONNECTION
            If server.Pending = True Then
                client = server.AcceptTcpClient
                clientData = New StreamReader(client.GetStream)
            End If
            ' RAISE EVENT FOR INCOMING MESSAGE
            Try
                RaiseEvent MessageReceived(Me, "[ " & DateTime.Now() & " ] " & clientData.ReadLine)
            Catch ex As Exception

            End Try
            ' REDUCE CPU USAGE
            Thread.Sleep(100)
        Loop
    End Sub
End Class

Selanjutnya kita kembali ke frm server dan tuliskan seluruh code berikut.

Source Code form Server

Public Class Form1
    Private server As TCPcontrolClass
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        server = New TCPcontrolClass
        TextBox1.Text = "Server Started" & vbCrLf
        AddHandler server.MessageReceived, AddressOf OnlineReceived
    End Sub

    Private Delegate Sub UpdateTextDelegate(TB As TextBox, txt As String)

    'UPDATE TEXTBOX
    Private Sub UpdateText(TB As TextBox, txt As String)
        If TB.InvokeRequired Then
            TB.Invoke(New UpdateTextDelegate(AddressOf UpdateText), New Object() {TB, txt})
        Else
            If txt IsNot Nothing Then TB.AppendText(txt & vbCrLf)
        End If
    End Sub

    Private Sub OnlineReceived(sender As TCPcontrolClass, Data As String)
        UpdateText(TextBox1, Data)
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        server.isListening = False
    End Sub
End Class


Jika sudah selesai, mari kita jalankan project server kamu, apabila setelah menjalankan aplikasi server, muncul pesan pada TextBox1 = "Server Started" maka kamu berhasil membuka koneksi kamu dan sedang mencari koneksi dari client yang nanti akan kita buat project baru untuk client kamu.

Project Cliet

Jika tidak ada masalah, langsung saja kita akan membuat Project baru lagi dengan nama "Client", dalam aplikasi ini saya (penulis) membuat nama "clientone" kamu bisa sesuaikan dengan kebutuhan kamu. Desainlah tampilan client seperti gambar berikut :
Client TCP
Buatlah Class Baru dengan nama "TCPcontroller.vb" dan tuliskan code berikut di TCPcontroller.vb

Source Code TCPcontroller Client Project
Imports System.IO
Imports System.Net
Imports System.Net.Sockets

Public Class TCPcontroller

    Public client As TcpClient
    Public clientData As StreamWriter

    Public Sub New(Host As String, Port As Integer)

        ' ITS FOR CLIENT CONFIGURATIONS
        client = New TcpClient(Host, Port)
        clientData = New StreamWriter(client.GetStream)
    End Sub

    Public Sub send(Data As String)
        clientData.Write(Data & vbCrLf)
        clientData.Flush()
    End Sub
End Class

Jika sudah selesai, kembali ke Form Client dan tuliskan juga code vb.net berikut

Source Code Form Client
Public Class Form1
    Private client As TCPcontroller
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        client = New TCPcontroller("127.0.0.1", 8080) ' ITS FOR YOUR SERVER IP ADDRESS AND PORT NUMBER
        If client.client.Connected Then Button1.Text = "Connected !!!"

    End Sub

    Private Sub SendMessage()

        If client.client.Connected = True Then client.send(TextBox1.Text)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        SendMessage()
        TextBox1.Clear()
        TextBox1.Focus()
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing

        If client.client.Connected = True Then
            client.clientData.Close()
            client.client.Close()
        End If
        ' lets try it

        ' you see?
        ' No connection could be made because the target machine actively refused it
        ' you must open your server before connect the client
        ' lets open the server

    End Sub
End Class

dan selamat, kamu sudah berhasil membuat aplikasi chat sederhana dengan menggunakan bahasa pemrograman vb.net. coba kamu jalankan project server terlebih dahulu dan kemudian jalankan juga project clientnya. sekarang kamu bisa menggunakan aplikasi chat tersebut dalam local network kamu.

Ini merupakan video tutorial yang sudah kami tuliskan diatas, agar lebih mudah dipahami silahkan dilihta video tutorial membuat Aplikasi Chat Sederhana Network Programming Client/Server

jika ada pertanyaan bisa mengirimkan e-mail kepada saya melalui contact form atau bisa juga melalui media sosial kami :

Google Plus : https://plus.google.com/+HarisonMatondang
Youtube : http://www.youtube.com/c/HarisonMatondang
Officel Website : Yuk ngoding sampai ngeh di ngehh.id

Jangan lupa share dan subscribe juga ya untuk mendapatkan tips dan trik serta tutorial programming terbaru setiap harinya.

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Programming VB.NET : Aplikasi Chat Sederhana Network Programming Client/Server
Programming VB.NET : Aplikasi Chat Sederhana Network Programming Client/Server
Belajar VB.Net khusus pemula : membuat aplikasi chat sederhana Client/Server Tcpclient dan MultiThread vb.net tutorial, selengkapnya di sector code
https://4.bp.blogspot.com/-K_PEVXO55r0/VvmKD_YMQNI/AAAAAAAABfQ/W2Cs4zGk-08WBZ2Y0AIPXDAgVg79HtvVQ/s320/client-server-multithread-vbnet.jpg
https://4.bp.blogspot.com/-K_PEVXO55r0/VvmKD_YMQNI/AAAAAAAABfQ/W2Cs4zGk-08WBZ2Y0AIPXDAgVg79HtvVQ/s72-c/client-server-multithread-vbnet.jpg
KODE AJAIB
https://www.kodeajaib.com/2016/03/vbnet-membuat-aplikasi-chat-tcpclient-multithread.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/03/vbnet-membuat-aplikasi-chat-tcpclient-multithread.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy