Could you help me? UDP Communication
-
hi i'm VB.net Newbi in south korea. it's difficult to me ;( . I am creating a UDP chat by looking at the data. The server cannot send a message to the client. I need help. how do i code it?? -Send-
Imports System.IO
Imports System.Net.Sockets.Socket
Imports System
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Public Class Form1Inherits System.Windows.Forms.Form Dim GLOIP As IPAddress Dim GLOINTPORT As Integer Dim bytCommand As Byte() = New Byte() {} Dim udpClient As New UdpClient Public receivingUdpClient As UdpClient Public RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0) Public ThreadReceive As System.Threading.Thread Dim SocketNO As Integer Private Sub cmdSend\_Click(sender As Object, e As EventArgs) Handles cmdSend.Click Dim pRet As Integer Try 'Get IP address GLOIP = IPAddress.Parse(txtIP.Text) 'Get Port GLOINTPORT = txtPort.Text 'Connect udpClient.Connect(GLOIP, GLOINTPORT) 'Get Message from text box, encode it bytCommand = Encoding.Unicode.GetBytes(txtMessage.Text) 'Send pRet = udpClient.Send(bytCommand, bytCommand.Length) txtInfo.Text = txtInfo.Text + vbCrLf + "The messege send is """ txtInfo.Text = txtInfo.Text & Encoding.Unicode.GetString(bytCommand) & """" Catch ex As Exception txtInfo.Text = txtInfo.Text & vbCrLf & ex.Message End Try End Sub 'txtMessage창에서 Enter키를 누르면 메시지를 전송하는 기능 Private Sub txtMessage\_KeyDown(sender As Object, e As KeyEventArgs) Handles txtMessage.KeyDown If e.KeyCode = Keys.Enter Then cmdSend.PerformClick() txtMessage.Clear() End If End Sub
End Class
--Receive--
Imports System.IO
Imports System
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Public receivingUdpClient As UdpClient
Public RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, 0)
Public ThreadReceive As System.Threading.Thread
Dim SocketNO As Integer
Public Delegate Sub SettheText(ByVal TextObject As TextBox, ByVal text As String)