Chat Tool : Chat « Socket Network « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Socket Network » Chat 
22.19.1.Chat Tool
Chat Tool
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text

Imports System.Windows.Forms

public class ChatTool
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(8816)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(13620)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(3216)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(4824)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Message"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(064)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(8024)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Target IP"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(8864)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(13620)
        Me.TextBox2.TabIndex = 3
        Me.TextBox2.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8104)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(7224)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "Record"
        '
        'TextBox3
        '
        Me.TextBox3.AutoSize = False
        Me.TextBox3.Location = New System.Drawing.Point(80104)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(184136)
        Me.TextBox3.TabIndex = 5
        Me.TextBox3.Text = ""
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(23216)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(5624)
        Me.Button1.TabIndex = 6
        Me.Button1.Text = "Send"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(292266)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.TextBox1)
        Me.ResumeLayout(False)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
        Dim bytes(200As Byte
        Dim MyIP As IPAddress
        Dim RemoteIP As IPAddress
        Dim str As String

        RemoteIP = IPAddress.Parse(TextBox2.Text)
        MyIP = IPAddress.Parse("912.168.1.100")

        Dim Port1 As Integer = 8080
        Dim port2 As Integer = 8081

        Dim myLocal As New IPEndPoint(MyIP, Port1)
        Dim myRemote As New IPEndPoint(RemoteIP, port2)
        Dim receive1 As New UdpClient(myRemote)
        Dim send1 As New UdpClient(myLocal)

        Try
            bytes = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text.ToUpper)
            send1.Send(bytes, bytes.Length, myRemote)
            str = System.Text.Encoding.ASCII.GetString(bytes)
            TextBox3.Text = TextBox3.Text & vbCrLf & str

            bytes = receive1.Receive(myLocal)
            str = System.Text.Encoding.ASCII.GetString(bytes)
            TextBox3.Text = TextBox2.Text & vbCrLf & str

            
        Catch ex As Exception
            Console.WriteLine("")
        End Try
        send1.Close()
        receive1.Close()
    End Sub
End Class
22.19.Chat
22.19.1.Chat ToolChat Tool
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.