THE UDPCHAT-Server Source (VB.NET) 'I Use Winsock Control SP5 (VB6) Public Class Frmmain Inherits System.Windows.Forms.Form # Region "Windows Form Designer Generated Code" Public Sub New () MyBase.new () 'This call is required for the Windows Form Designer. InitializationComponent () 'Add any initialization End Sub' form rewriting to clean the component list after the initializationComponent () call. Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub 'Windows Form Designer Private components required As system.componentmodel.icontainer 'Note: The following procedure is required to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.
Friend WithEvents txtChatLog As System.Windows.Forms.TextBox Friend WithEvents pelSaid As System.Windows.Forms.Panel Friend WithEvents txtSaid As System.Windows.Forms.TextBox Friend WithEvents btnSend As System.Windows.Forms.Button Friend WithEvents sckServer As AxMSWinsockLib. AxWinsock
New system.drawing.point (0, 332) me.pelsaid.name = "PLSAID" me.pelsaid.size = new system.drawing.size (392, 34) me.pelsaid.tabindex = 1 '' btnsend 'me. Btnsend.location = new system.drawing.point (296, 5) me.btnsend.name = "btnsend" me.btnsend.size = new system.drawing.size (80, 24) me.btnsend.tabindex = 0 me. Btnsend.text = "send" '' txtsaid 'me.txtsaid.location = new system.drawing.point (8, 6) me.txtsaid.name = "txtsAid" me.txtsAid.size = new system.drawing.size 280, 21) me.txtsaid.tabindex = 0 me.txtsaid.text = "" 'Sckserver' me.sckserver.enabled = true me.sckserver.location = new system.drawing.point (16, 8) me.sckserver .Name = "Sckserver" me.sckserver.ocxState = ctype (Resources.GetObject ("Sckserver.OCxState"), System.Windows.Forms.axhost.State) me.sckserver.size = new system.drawing.size (28, 28) Me.sckServer.TabIndex = 2 '' frmMain 'Me.AutoScaleBaseSize = New System.Drawing.Size (6, 14) Me.ClientSize = New System.Drawing.Size (392, 366) Me.Controls.AddRange (New System. Windows.Forms.Control () {Me.sckServer, Me.pelSaid, Me.txtChatLog}) Me.MaximizeBox = False Me.MaximumSize = New System.Drawing.Size (400, 400) Me.MinimumSize = New System.Drawing. Size (400, 400) me.name = "frmmain" me.startPosition =
System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "UDPChat-Server" Me.pelSaid.ResumeLayout (False) CType (Me.sckServer, System.ComponentModel.ISupportInitialize) .EndInit () Me.ResumeLayout (False) End Sub #End Region # Region "Winsock Event" Private Sub sckServer_ConnectionRequest (ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles sckServer.ConnectionRequest txtChatLog.AppendText ( "Request of Connecting from" & e.requestID & vbCrLf) txtChatLog.AppendText ( "Request Accepted ...." & vbCrLf) sckServer.Accept (e.requestID) sckServer.SendData ( "Connection Accepted ...." & vbCrLf) End Sub Private Sub sckServer_DataArrival (ByVal sender As Object, ByVal e As AxMSWinsockLib. DMSWinsockControlevents_DataArrivalEvent) Handles Sckserver.DataArrival Dim Objdata As Object Sckserver.Getdata (ObjData, VBString) TxtChatlog.AppendText ("Client: & CSTR (ObjData) & vbCrLf) End Sub # End Region Private Sub frmMain_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load sckServer.RemoteHost = "127.0.0.1" sckServer.RemotePort = 8000 sckServer.Bind (1000) txtChatLog .AppendText ( "binded to localhost at 1000 and Remote port 8000" & vbCrLf) End Sub Private Sub btnSend_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click If txtSaid.Text.Trim = "" THEN MSGBOX ("Please Input the chat the contents", msgboxstyle.okonly, "udpchat-server"
) Exit Sub End If Try txtChatLog.AppendText ( "Server:" & txtSaid.Text & vbCrLf) sckServer.SendData (CType (txtSaid.Text, Object)) txtSaid.Text = "" Catch MsgBox ( "Error Occured" & Err. Description & vbCrLf & Err.Number, MsgBoxStyle.OKOnly, "UDPChat-Server") End Try End Sub Private Sub txtSaid_KeyPress (ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSaid.KeyPress If (e. Keychar = chr (13)) THEN BTNSEND_CLICK (Sender, new system.eventargs ()) end if End suend classthe udpchat-client source (vb.net)
'I Use Winsock Control SP5 (VB6) Public Class FRMMAIN Inherits System.Windows.Forms.Form # Region "Windows Form Designer Generated Code" PUBLIC SUB New () MyBase.new ()' This call is Windows Form Design The device is required. InitializationComponent () 'Add any initialization End Sub' form rewriting to clean the component list after the initializationComponent () call. Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub 'Windows Form Designer Private components required As system.componentmodel.icontainer 'Note: The following procedure is required to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.
Friend WithEvents pelSaid As System.Windows.Forms.Panel Friend WithEvents btnSend As System.Windows.Forms.Button Friend WithEvents txtSaid As System.Windows.Forms.TextBox Friend WithEvents txtChatLog As System.Windows.Forms.TextBox Friend WithEvents sckClient As AxMSWinsockLib. AxWinsock
New system.drawing.point (8, 6) me.txtsaid.name = "txtsAid" me.txtsaid.size = new system.drawing.size (280, 21) me.txtsaid.tabindex = 0 me.txtsaid.text = "" '' txtChatLog 'Me.txtChatLog.Dock = System.Windows.Forms.DockStyle.Top Me.txtChatLog.Multiline = True Me.txtChatLog.Name = "txtChatLog" Me.txtChatLog.ReadOnly = True Me.txtChatLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.txtChatLog.Size = New System.Drawing.Size (392, 328) Me.txtChatLog.TabIndex = 3 Me.txtChatLog.TabStop = False Me.txtChatLog.Text = "" '' sckClient 'Me.sckClient.Enabled = True Me.sckClient.Location = New System.Drawing.Point (16, 8) Me.sckClient.Name = "sckClient" Me.sckClient.OcxState = CType (resources.GetObject ( "sckClient. OcxState "), system.windows.forms.axhost.state) Me.sckclient.size = new system.drawing.size (28, 28) me.sckcl ient.TabIndex = 4 '' frmMain 'Me.AutoScaleBaseSize = New System.Drawing.Size (6, 14) Me.ClientSize = New System.Drawing.Size (392, 366) Me.Controls.AddRange (New System.Windows. Forms.Control () {Me.sckClient, Me.txtChatLog, Me.pelSaid}) Me.MaximizeBox = False Me.MaximumSize = New System.Drawing.Size (400, 400) Me.MinimumSize = New System.Drawing.Size ( 400, 400) me.name = "frmmain" me.startPosition = system.windows.forms.formstartPosition.CenterScreen me.text = "
UDPChat-Client "Me.pelSaid.ResumeLayout (False) CType (Me.sckClient, System.ComponentModel.ISupportInitialize) .EndInit () Me.ResumeLayout (False) End Sub # End Region # Region" Winsock Event "Private Sub sckClient_ConnectEvent (ByVal sender As Object, ByVal e As System.EventArgs) Handles sckClient.ConnectEvent txtChatLog.AppendText ( "Connected to" & sckClient.RemoteHost & vbCrLf) txtChatLog.AppendText ( "Socket State is" & sckClient.SocketHandle & vbCrLf) End Sub Private Sub sckClient_DataArrival (ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles sckClient.DataArrival Dim objData As Object sckClient.GetData (objData, vbString) txtChatLog.AppendText ( "Server:" & CStr (objData) & vbCrLf) End Sub # End Region private sub frmmain_load (byval e as system.EventArgs) Handles mybase.load sckclient.remotehost = "127.0.0.1" Sckclient.remoteport = 1000 sckClient.Bind (8000) txtChatLog.AppendText ( "Bind to local Port 8000 and remote port 1000" & vbCrLf) End Sub Private Sub btnSend_Click (ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click If txtSaid .Text.Trim = "" Then MsgBox ( "Please input the chat the contents", MsgBoxStyle.OKOnly, "UDPChat-Client") Exit Sub End If Try txtChatLog.AppendText ( "Client:" & txtSaid.Text & vbCrLf) sckClient .Senddata (ctype (txtsaid.text, object) txtsaid.text = "" "Catch Msgbox ("