[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.....
http://i532.photobucket.com/albums/e...dney29/Sc1.jpg
*Here's my chat Room image:
http://i532.photobucket.com/albums/e...dney29/Sc2.jpg
This will sample program i make and if this work i transfer it into my original program...
Can you help me pls...
Re: Chatting with networking
What language are you using? If VB6 then have a search for winsock.
Re: Chatting with networking
yup vb6...
any sample? can you share me, i have no idea eh...
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?"
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"....
Re: [VB6] Local Area Network Game
no one can reply my post
I need your answer plss...
Re: [VB6] Local Area Network Game
Search for winsock.
There are TONS of examples if one searches for them.
Re: [VB6] Local Area Network Game
but i search everywhere with displaying list of server/host it into a listbox
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
Quote:
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.
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
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
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
Re: [VB6] Local Area Network Game
I just figuring out my first problem
Here's are some imgae:
http://i532.photobucket.com/albums/e...sAClient_1.jpg
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...