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