Last active
October 14, 2019 17:31
-
-
Save ryasmi/4475422 to your computer and use it in GitHub Desktop.
Lan Chat basics in Visual Basic using the TCP. The code below is based on my YouTube tutorial (http://www.youtube.com/watch?v=Pd8TGRrDDMc&list=PL63C2673281C99172&index=3).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Tutorial @ http://www.youtube.com/watch?v=Pd8TGRrDDMc&list=PL63C2673281C99172&index=3 | |
Option Explicit On | |
Imports System.IO | |
Imports System.Net.Sockets | |
Public Class Form1 | |
Dim Listener As New TcpListener(8000) | |
Dim Client As TcpClient | |
Private Sub _FormClosing() Handles Me.FormClosing | |
Listener.Stop() | |
End Sub | |
Private Sub _Load() Handles MyBase.Load | |
Timer1.Start() | |
Listener.Start() | |
End Sub | |
Private Sub _Tick() Handles Timer1.Tick | |
Dim Message As String | |
Dim nStart As Integer | |
Dim nLast As Integer | |
If Listener.Pending = True Then | |
Message = "" | |
Client = Listener.AcceptTcpClient() | |
Dim Reader As New StreamReader(Client.GetStream()) | |
While Reader.Peek > -1 | |
Message &= Convert.ToChar(Reader.Read()).ToString | |
End While | |
If Message.Contains("</>") Then | |
nStart = InStr(Message, "</>") + 4 | |
nLast = InStr(Message, "<\>") | |
Message = Mid(Message, nStart, nLast - nStart) | |
End If | |
Label1.Text = Message | |
End If | |
End Sub | |
End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Tutorial @ http://www.youtube.com/watch?v=Pd8TGRrDDMc&list=PL63C2673281C99172&index=3 | |
Option Explicit On | |
Imports System.IO | |
Imports System.Net.Sockets | |
Public Class Form1 | |
Dim Client As TcpClient | |
Private Sub btnClick() Handles Button1.Click | |
Try | |
Client = New TcpClient("127.0.0.1", 8000) | |
Dim Writer As New StreamWriter(Client.GetStream()) | |
Writer.Write("</> " & TextBox1.Text & " <\>" | |
Writer.Flush | |
Catch ex As Exception | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi ryan I got little Problem I don't know how to show them in every single text box in receiver thank you. [email protected]
Sender
Option Explicit On
Imports System.IO
Imports System.Net.Sockets
Public Class Form1
End Class
receiver
Option Explicit On
Imports System.IO
Imports System.Net.Sockets
Public Class Form1
Dim Listener As New TcpListener(8000)
Dim Client As TcpClient
End Class