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. Visual Basic
  4. help send data to new connected user

help send data to new connected user

Scheduled Pinned Locked Moved Visual Basic
helpsysadmintutorial
2 Posts 2 Posters 8 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.
  • B Offline
    B Offline
    Benjamindh
    wrote on last edited by
    #1

    Hello everyone, I have the following code that works perfectly without problems When sending the data throughout the network, but I have a problem that I cannot solve And it happens that When a client executes the program, it does Not receive the data from the other clients that are are connected only receives the data When New data Is sent.

    Example someone connects And In the listview the information that the other users sent Is loaded because they are online, but If another connects they cannot see that information, what I want To Do Is To wait If a client connects again this I send you the information that Is In the listview

    #Region "Variables"
    'Object variable containing the socket
    Dim ElSocket As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)

    'Variable that contains the thread in charge of receiving the data
    Dim HiloRecibir As Thread
    
    'Variable that indicates whether the program is closing
    Dim Saliendo As Boolean = False
    
    'Temporary variables to store received data
    Dim DireccIP As String, ContenidoMensaje As String
    

    #End Region

    'WE RECEIVE THE SUBMITTED DATA
    Private Sub RecibirDatos()
        'As long as the output indicator is not true
        Do Until Saliendo
    
            'Variable to get the IP of the sender machine
            Dim LaIPRemota As New IPEndPoint(IPAddress.Any, 0)
            'Variable to store ip temporarily
            Dim IPRecibida As EndPoint = CType(LaIPRemota, EndPoint)
            Dim RecibirBytes(255) As Byte 'Buffer
            Dim Datos As String = "" 'Text a Show
    
            Try
                'Receive the data                
                ElSocket.ReceiveFrom(RecibirBytes, RecibirBytes.Length, SocketFlags.None, IPRecibida)
                'converts them and saves it in the data variable
                Datos = Encoding.Default.GetString(RecibirBytes)
            Catch ex As SocketException
                If ex.ErrorCode = 10040 Then ' data too long                    
                    Datos &= "\[truncado\]" 'add the string "\[truncated\]" to the received text                
                Else
                    'displays the error message
    

    MsgBox("Error '" & ex.ErrorCode.ToString & "' " & ex.Message, MsgBoxStyle.Critical, " Error receiving data ")
    End If
    End Try

            'converts the endpoint type to ipendpoint with its respective variables
            LaIPRemota = CType(IPRecibida, IPEndP
    
    R 1 Reply Last reply
    0
    • B Benjamindh

      Hello everyone, I have the following code that works perfectly without problems When sending the data throughout the network, but I have a problem that I cannot solve And it happens that When a client executes the program, it does Not receive the data from the other clients that are are connected only receives the data When New data Is sent.

      Example someone connects And In the listview the information that the other users sent Is loaded because they are online, but If another connects they cannot see that information, what I want To Do Is To wait If a client connects again this I send you the information that Is In the listview

      #Region "Variables"
      'Object variable containing the socket
      Dim ElSocket As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)

      'Variable that contains the thread in charge of receiving the data
      Dim HiloRecibir As Thread
      
      'Variable that indicates whether the program is closing
      Dim Saliendo As Boolean = False
      
      'Temporary variables to store received data
      Dim DireccIP As String, ContenidoMensaje As String
      

      #End Region

      'WE RECEIVE THE SUBMITTED DATA
      Private Sub RecibirDatos()
          'As long as the output indicator is not true
          Do Until Saliendo
      
              'Variable to get the IP of the sender machine
              Dim LaIPRemota As New IPEndPoint(IPAddress.Any, 0)
              'Variable to store ip temporarily
              Dim IPRecibida As EndPoint = CType(LaIPRemota, EndPoint)
              Dim RecibirBytes(255) As Byte 'Buffer
              Dim Datos As String = "" 'Text a Show
      
              Try
                  'Receive the data                
                  ElSocket.ReceiveFrom(RecibirBytes, RecibirBytes.Length, SocketFlags.None, IPRecibida)
                  'converts them and saves it in the data variable
                  Datos = Encoding.Default.GetString(RecibirBytes)
              Catch ex As SocketException
                  If ex.ErrorCode = 10040 Then ' data too long                    
                      Datos &= "\[truncado\]" 'add the string "\[truncated\]" to the received text                
                  Else
                      'displays the error message
      

      MsgBox("Error '" & ex.ErrorCode.ToString & "' " & ex.Message, MsgBoxStyle.Critical, " Error receiving data ")
      End If
      End Try

              'converts the endpoint type to ipendpoint with its respective variables
              LaIPRemota = CType(IPRecibida, IPEndP
      
      R Offline
      R Offline
      Raphael Adeniji
      wrote on last edited by
      #2

      Hi Benjamin. I did something similar to this in Visual Basic using windows functions (DLL) in those days. I called it broadcast. However, your issue is not very difficult because those clients that are online receive your message, but anyone just connecting will not receive it after the broadcast. What you have to do is to store and forward your messages for the clients that are offline. You can achieve this by storing your message and client ID on a database or a file for the clients that are online at the time of sending message out, then you will have a sort of service program that will forward the message later for new clients just connecting to the network. Remember every system has a unique computer name (ID) on windows network. When you send the message out, you keep the IDs of those online and the service program will later forward to new online clients and store their IDs too. Note that you may also have to generate unique message ID also to filter.

      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