Click here to Skip to main content
15,438,920 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: close app without having form in foreground Pin
Dave Kreskowiak11-Mar-22 3:40
mveDave Kreskowiak11-Mar-22 3:40 
GeneralRe: close app without having form in foreground Pin
Benjamindh19-Mar-22 17:47
MemberBenjamindh19-Mar-22 17:47 
SuggestionRe: close app without having form in foreground Pin
Richard Deeming3-Mar-22 21:29
mveRichard Deeming3-Mar-22 21:29 
QuestionCrystal report viewer 8.5 y visual basic 2005 Pin
Member 119485295-Feb-22 17:58
MemberMember 119485295-Feb-22 17:58 
AnswerRe: Crystal report viewer 8.5 y visual basic 2005 Pin
CHill602-Mar-22 4:20
mveCHill602-Mar-22 4:20 
Questionremove item without being selected only with the name Pin
Benjamindh27-Jan-22 4:38
MemberBenjamindh27-Jan-22 4:38 
AnswerRe: remove item without being selected only with the name Pin
Victor Nijegorodov27-Jan-22 5:30
MemberVictor Nijegorodov27-Jan-22 5:30 
Questionhelp send data to new connected user Pin
Benjamindh26-Jan-22 5:46
MemberBenjamindh26-Jan-22 5:46 
 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



VB
 #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, IPEndPoint)
            'saves the data in temporary variables
            DireccIP = LaIPRemota.Address.ToString
            ContenidoMensaje = Datos.ToString
            LNetgames.Invoke(New EventHandler(AddressOf ActualizarTextoMensaje))

        Loop
    End Sub

    'ADD DATA RECEIVED
    Protected Sub ActualizarTextoMensaje(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim line As String = ContenidoMensaje
        Dim parts() As String = line.Split("|"c)
        'I now decode the bytes and pass them to the listview
        Dim item As New ListViewItem()
        item.Text = parts(0)
        For i As Integer = 1 To parts.Length - 1
            item.SubItems.Add(parts(i))
        Next
        LNetgames.Items.Add(item)

    End Sub

    'LOAD THE DATA
    Private Sub LoadSocket()
        'We separate the port 200145 to use it in our application        
        ElSocket.Bind(New IPEndPoint(IPAddress.Any, 20145))
        'We enable the Broadcast option for the socket
        ElSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, True)
        HiloRecibir = New Thread(AddressOf RecibirDatos) 'Create the thread
        HiloRecibir.Start() 'Start the thread
    End Sub

    <Obsolete>
    Private Sub EnviarDatos()
        Dim IpExternal = GetComputer_InternetIP()
        Dim host_name As String = Dns.GetHostName()
        Dim ip_address As String = Dns.GetHostByName(host_name).AddressList(0).ToString()
        Dim HHusuario As String = "config\usuario.txt"
        Dim Player1 As String
        Player1 = System.IO.File.ReadAllText(HHusuario)
        'Contains the Broadcast address and the port used
        Dim DirecciónDestino As New IPEndPoint(IPAddress.Broadcast, 20145)
        'Buffer that will hold the data until it is sent
        Dim DatosBytes As Byte() = Encoding.Default.GetBytes(LNetgames.Text)
        'Send the data
        ElSocket.SendTo(DatosBytes, DatosBytes.Length, SocketFlags.None, DirecciónDestino)
    End Sub


modified 26-Jan-22 11:52am.

AnswerRe: help send data to new connected user Pin
Raphael Adeniji7-May-22 5:43
MemberRaphael Adeniji7-May-22 5:43 
QuestionHelp add data received from a TCP in each Columns Pin
Benjamindh19-Jan-22 4:47
MemberBenjamindh19-Jan-22 4:47 
AnswerRe: Help add data received from a TCP in each Columns Pin
Richard Deeming19-Jan-22 5:38
mveRichard Deeming19-Jan-22 5:38 
GeneralRe: Help add data received from a TCP in each Columns Pin
Benjamindh19-Jan-22 14:23
MemberBenjamindh19-Jan-22 14:23 
QuestionOpen, read and extract pdf's doc. Pin
Member 1490245413-Jan-22 4:16
MemberMember 1490245413-Jan-22 4:16 
AnswerRe: Open, read and extract pdf's doc. Pin
Dave Kreskowiak13-Jan-22 5:19
mveDave Kreskowiak13-Jan-22 5:19 
GeneralRe: Open, read and extract pdf's doc. Pin
Member 1490245413-Jan-22 7:55
MemberMember 1490245413-Jan-22 7:55 
GeneralRe: Open, read and extract pdf's doc. Pin
Dave Kreskowiak13-Jan-22 8:33
mveDave Kreskowiak13-Jan-22 8:33 
GeneralRe: Open, read and extract pdf's doc. Pin
Member 1490245414-Jan-22 0:25
MemberMember 1490245414-Jan-22 0:25 
AnswerRe: Open, read and extract pdf's doc. Pin
CHill6014-Jan-22 1:27
mveCHill6014-Jan-22 1:27 
QuestionHow do I get the propertyname of WPF control? Pin
Steve Krozer7-Jan-22 0:30
MemberSteve Krozer7-Jan-22 0:30 
Rant[REPOST] How do I get the propertyname of WPF control? Pin
Richard Deeming7-Jan-22 0:38
mveRichard Deeming7-Jan-22 0:38 
QuestionExtracting username from a access database to show username after logging on Pin
Jeremy Haley 20226-Jan-22 4:14
MemberJeremy Haley 20226-Jan-22 4:14 
AnswerRe: Extracting username from a access database to show username after logging on Pin
Richard MacCutchan6-Jan-22 5:47
mveRichard MacCutchan6-Jan-22 5:47 
GeneralRe: Extracting username from a access database to show username after logging on Pin
Jeremy Haley 20226-Jan-22 5:55
MemberJeremy Haley 20226-Jan-22 5:55 
GeneralRe: Extracting username from a access database to show username after logging on Pin
Richard MacCutchan6-Jan-22 6:53
mveRichard MacCutchan6-Jan-22 6:53 
SuggestionRe: Extracting username from a access database to show username after logging on Pin
Richard Deeming6-Jan-22 5:57
mveRichard Deeming6-Jan-22 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.