Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Could you help me? UDP Communication

Could you help me? UDP Communication

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpsysadminhelp
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15480216
    wrote on last edited by
    #1

    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 Form1

    Inherits 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)

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups