Results 1 to 13 of 13

Thread: [VB6] Local Area Network Game

  1. #1

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    [VB6] Local Area Network Game

    I have created a program that has a LAN game
    but i don't know how it to see the host list that can join to host game i've created a listbox to list all of the host that created and the user/client wants to join them by choosing the list of hosted..

    *here's my image:

    In my game list.....



    *Here's my chat Room image:



    This will sample program i make and if this work i transfer it into my original program...
    Can you help me pls...
    Last edited by morkie; Sep 6th, 2009 at 05:41 PM.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Chatting with networking

    What language are you using? If VB6 then have a search for winsock.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: Chatting with networking

    yup vb6...
    any sample? can you share me, i have no idea eh...

  4. #4

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: Chatting with networking

    Can you help me plss...
    on how many user's try to create a host and listed it into listbox.
    what code i've use to see the host name listed in the listbox..
    should i use a "listbox.additem on it?"
    Last edited by morkie; Sep 6th, 2009 at 05:39 PM.

  5. #5

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: [VB6] Local Area Network Game

    Can anyone help me for this

    By creating a lot of user host and displaying it into listbox
    then client wants to join it by choosing list of host in
    listbox display...
    that what i want's to know "displaying a host list in listbox"....
    Last edited by morkie; Sep 6th, 2009 at 05:36 PM.

  6. #6

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: [VB6] Local Area Network Game

    no one can reply my post
    I need your answer plss...

  7. #7
    Member
    Join Date
    Mar 2006
    Posts
    46

    Re: [VB6] Local Area Network Game

    Search for winsock.
    There are TONS of examples if one searches for them.

  8. #8

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: [VB6] Local Area Network Game

    but i search everywhere with displaying list of server/host it into a listbox

  9. #9
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [VB6] Local Area Network Game

    You probably need to study a bit more about network technology.
    It looks like you want to create a single program that can act as Server or Client.
    You would need different coe for both parts.
    The server can wait for Clients to connect, after connection the Server can display the Clients.
    A Client can connect to the Server, the problem is to know who the Server is.

    I don't understand what your
    By creating a lot of user host and displaying it into listbox
    then client wants to join it by choosing list of host in
    listbox display...
    is meant to be. Are those "User Hosts" already connected or not? Are they Servers or Clients?

    I'd suggest you to read more about Winsock.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  10. #10

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: [VB6] Local Area Network Game

    These user host is a server that listening
    and the client can join/connect with those server listed it into listbox

    I have no problem about conecting a server and client
    I have tested it before using a chat program...

    Here's my work but this is not done yet...
    In my work this will connect both from PC by clicking join Game button but i want to ask how to detect ip address of the computers that are connected to LAN. Thanks

    Code:
    Private Const DiscoveryPort As Long = 4111
    Private Const ResponsePort As Long = 4112
    
    Private Const TCP_ListenPort As Long = 4511
    
    Private Const DiscoveryPortClient As Long = 4112 ' ports are reversed from the server
    Private Const ResponsePortClient As Long = 4111
    Private ServerIP As String
    Private ServerPort As Long
    
    
    
    Private Sub createGame_Click()
    If txtplayername = "" Then
    MsgBox ("Enter Name first")
    Else
    ' Prepare UDP Broadcasting and UDP Listeing
        With SckUDP
            .Close
            .Protocol = sckUDPProtocol
            .RemoteHost = "255.255.255.255"
            .LocalPort = DiscoveryPort
            .RemotePort = ResponsePort
            
            ' start listening for UDP packets
            .Bind DiscoveryPort
        End With
        
    ListenTCP
    End If
    Timer2.Enabled = True
    frmInGame.Show
    End Sub
    Private Sub ListenTCP()
        With SckTCP
            .Close
            .LocalPort = TCP_ListenPort
            
            ' Start listening for TCP connections
            .Listen
            
        End With
    End Sub
    
    Private Sub lstGame_Click()
    'Dim i As Integer
    'For i = 0 To 7
    If lstGame.Selected(0) = True Then
    lblmessageresult.Caption = txtplayername.Text
    Timer1.Enabled = False
    Timer2.Enabled = False
    End If
    'Next i
    End Sub
    
    Private Sub SckTCP_Close()
    SckTCP.Close
    ListenTCP
    End Sub
    Private Sub SckTCP_ConnectionRequest(ByVal requestID As Long)
    SckTCP.Close
    SckTCP.Accept requestID
    End Sub
    Private Sub JoinGame_Click()
    If lstGame.ListCount < 1 Then
    lblmessageresult.Caption = "Can't Join the Game!.^_^.!"
    Else
        If lstGame.Selected(0) = True Then
        sockfrm1.Protocol = sckUDPProtocol
        sockfrm1.RemoteHost = "255.255.255.255"
        sockfrm1.LocalPort = DiscoveryPortClient
        sockfrm1.RemotePort = ResponsePortClient
        sockfrm1.Bind DiscoveryPortClient
    
        ' Broadcast, and ask where the server is
        sockfrm1.SendData "CLIENT|What's your IP ?"
    
        Timer1.Enabled = True
        Timer2.Enabled = False
        JoinGame.Enabled = False
        End If
    End If
    End Sub
    Private Sub loadhost_Click()
    formingame = frmInGame.lvlplayer1.Caption
    If Timer2.Enabled = False Then
    lblmessageresult.Caption = "No one can create the Game!.!"
    Else
        If lstGame.ListCount < 1 Then
        lblmessageresult.Caption = "no server found"
            Else
                If lstGame.Selected(0) = True Then
            sockfrm1.Protocol = sckUDPProtocol
            sockfrm1.RemoteHost = "255.255.255.255"
            sockfrm1.LocalPort = DiscoveryPortClient
            sockfrm1.RemotePort = ResponsePortClient
            sockfrm1.Bind DiscoveryPortClient
    
            ' Broadcast, and ask where the server is
            sockfrm1.SendData "CLIENT|What's your IP ?"
    
            Timer1.Enabled = True
            Timer2.Enabled = False
            End If
        End If
    lstGame.AddItem
    'lstGame.AddItem txtplayername.Text
    End If
    End Sub
    Private Sub Form_Load()
    
    Timer1.Enabled = False
    Timer2.Enabled = False
    End Sub
    Private Sub SckUDP_DataArrival(ByVal bytesTotal As Long)
    Dim MSG As String
        
        ' Received message from client
        SckUDP.GetData MSG, vbString
        
        ' Check if message is from a "friendly" application (our client application)
        If MSG = "CLIENT|What's your IP ?" Then
            ' Broadcast back our IP and TCP port number
            SckUDP.SendData "SERVER|" & SckUDP.LocalIP & "," & TCP_ListenPort
        End If
        
    End Sub
    Private Sub sockfrm1_DataArrival(ByVal bytesTotal As Long)
        Dim MSG As String
    
        ' Received message from server
        sockfrm1.GetData MSG, vbString
    
    If MSG Like "SERVER|*" Then ' Received message from server
            ServerIP = Split(Split(MSG, "|")(1), ",")(0)
            ServerPort = Val(Split(Split(MSG, "|")(1), ",")(1))
            
            If Len(ServerIP) > 0 And ServerPort > 0 Then
                ConnectToServer
            End If
            End If
    End Sub
    Private Sub ConnectToServer()
        With sockfrm1TCP
            .Close
            .RemoteHost = ServerIP
            .RemotePort = ServerPort
            .Connect
        End With
    End Sub
    Private Sub Timer1_Timer()
    Dim TmpStrr As String
        
        TmpStrr = "Client - " & Choose(sockfrm1TCP.State + 1, "Closed", "Open", "Listening", "Connection pending", "Resolving host", "Host resolved", "Connecting", "Connected", "Server is disconnecting", "Error")
        
        If lblmessageresult.Caption <> TmpStrr Then lblmessageresult.Caption = TmpStrr
        
    End Sub
    Private Sub Timer2_Timer()
    Dim TmpStr As String
        
        TmpStr = "Server - " & Choose(SckTCP.State + 1, "Closed", "Open", "Listening", "Connection pending", "Resolving host", "Host resolved", "Connecting", "Connected", "Server is disconnecting", "Error")
        
        If lblmessageresult.Caption <> TmpStr Then lblmessageresult.Caption = TmpStr
    End Sub
    Private Sub Cancel_Click()
    End
    End Sub
    Last edited by morkie; Sep 7th, 2009 at 11:27 AM.

  11. #11
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [VB6] Local Area Network Game

    Try working with the DOS-Command "net view" and have a look into this thread:
    http://www.dreamincode.net/forums/showtopic24549.htm
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  12. #12

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: [VB6] Local Area Network Game

    The code is VB.net
    how can i use it on VB6...and they use up a reference to System.Net.DLL

  13. #13

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: [VB6] Local Area Network Game

    I just figuring out my first problem

    Here's are some imgae:



    And now my question is
    how can the client joint it when user select an items in listbox (the listbox that display list of server's)

    and join it together to server...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width