分享
 
 
 

The UDPChat Source(VB.NET)

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

The UDPChat-Server Source(VB.NET)

'I use Winsock Control SP5(VB6)

Public Class frmMain

Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()

MyBase.New()

'该调用是 Windows 窗体设计器所必需的。

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写处置以清理组件列表。

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 窗体设计器所必需的

Private components As System.ComponentModel.IContainer

'注意:以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程。

'不要使用代码编辑器修改它。

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

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))

Me.txtChatLog = New System.Windows.Forms.TextBox()

Me.pelSaid = New System.Windows.Forms.Panel()

Me.btnSend = New System.Windows.Forms.Button()

Me.txtSaid = New System.Windows.Forms.TextBox()

Me.sckServer = New AxMSWinsockLib.AxWinsock()

Me.pelSaid.SuspendLayout()

CType(Me.sckServer, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'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 = 0

Me.txtChatLog.TabStop = False

Me.txtChatLog.Text = ""

'

'pelSaid

'

Me.pelSaid.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnSend, Me.txtSaid})

Me.pelSaid.Dock = System.Windows.Forms.DockStyle.Bottom

Me.pelSaid.Location = New System.Drawing.Point(0, 332)

Me.pelSaid.Name = "pelSaid"

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 Sub

End Class

The UDPChat-Client Source(VB.NET)

'I use Winsock Control SP5(VB6)

Public Class frmMain

Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()

MyBase.New()

'该调用是 Windows 窗体设计器所必需的。

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写处置以清理组件列表。

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 窗体设计器所必需的

Private components As System.ComponentModel.IContainer

'注意:以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程。

'不要使用代码编辑器修改它。

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

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))

Me.pelSaid = New System.Windows.Forms.Panel()

Me.btnSend = New System.Windows.Forms.Button()

Me.txtSaid = New System.Windows.Forms.TextBox()

Me.txtChatLog = New System.Windows.Forms.TextBox()

Me.sckClient = New AxMSWinsockLib.AxWinsock()

Me.pelSaid.SuspendLayout()

CType(Me.sckClient, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'pelSaid

'

Me.pelSaid.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnSend, Me.txtSaid})

Me.pelSaid.Dock = System.Windows.Forms.DockStyle.Bottom

Me.pelSaid.Location = New System.Drawing.Point(0, 332)

Me.pelSaid.Name = "pelSaid"

Me.pelSaid.Size = New System.Drawing.Size(392, 34)

Me.pelSaid.TabIndex = 2

'

'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 = ""

'

'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.sckClient.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 sender As System.Object, 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("Error Occured " & Err.Description & vbCrLf & Err.Number, MsgBoxStyle.OKOnly, "UDPChat-Client")

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 Sub

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有