So, I am trying to make a card game where I will be needing to send network over the network..This is being focused more toward LAN because I am deploying and I won't have WiFi etc, but I want to be able to play this card game that I am making with my friends in my berthing area but don't want it on the same laptop...
The game is handled all inside 1 application where a person can decide to be a host and 1 other person connects to that host and they both go against eachother...here is my multiplayer code (the connection works because it's copy paste atm from agk), however, I cannot seem to figure out how to make the client see things that the host can see...I am trying to figure this out by sending some data from host to client to see if the client can get anything from the host and move on from there...Here is what I got...
Host_Server:
DeleteVirtualButton(button_host)
DeleteVirtualButton(button_join)
networkId = HostNetwork("ZarkanEntertainment", "Host", 4100)
Do
Gosub Update_Cursor
If networkId > 0 and IsNetworkActive(networkId)
Print("Network Active....")
Else
Print("Network Setup Failed...")
EndIf
Print("Attempting to send data...")
//This will attempt to send the card to the client
card = CreateNetworkMessage()
AddNetworkMessageInteger(card, 1518)
SendNetworkMessage(networkId, 0, card)
DeleteNetworkMessage(card)
Sync()
Loop
Return
Join_Server:
networkId = JoinNetwork("ZarkanEntertainment", "Client")
connectTime# = Timer()
// 0 = connecting, 1 = connected, -1 = network closed, -2 = connection failed
state = 0
DeleteVirtualButton(button_host)
DeleteVirtualButton(button_join)
Do
Gosub Update_Cursor
// if a network is running, find the number of clients
clientNum = 0
if state >= 0
clientNum = GetNetworkNumClients(networkId)
endif
// if we are currently attempting to connect
if state = 0
Print("Connection Pending...")
// if the number of clients is greater than 1, the connection has succeeded
// this is because once connected, there must be a minimum of 2 clients (this machine and the host)
if clientNum > 1
state = 1 // indicate that we are now connected
// if the connection has not yet succeeded, check for a time out or an error
// if it takes longer than 5 seconds to connect, it is safe to assume that it has failed
// any time isnetworkactive returns 0 also indicates a failure
// reasons for failure might include there being no such network as ExampleNetwork
elseif Timer() - connectTime# > 5.0 or IsNetworkActive(networkId) = 0
state = -2 // indicate that the connection failed
// close the network so that we are free to attempt another connection
CloseNetwork(networkId)
endif
// if we are currently connected
elseif state = 1
// check that no errors have occured on the connection
if IsNetworkActive(networkId)
// print the network details and the details of this client
Print("Network Active")
Print("Network Clients Detected: " + Str(clientNum))
clientId = GetNetworkMyClientId(networkId)
Print("Server Id: " + Str(GetNetworkServerId(networkId)))
Print("Client Id: " + Str(clientId))
Print("Client Name: " + GetNetworkClientName(networkId, clientId))
else
Print("Network Inactive")
endif
// if the network has been closed deliberately, display a success message
elseif state = -1
Print("Network Closed")
// if the network connection has failed, display an error message
elseif state = -2
Print("Network Connection Failed")
endif
// if we are currently connected, give the user the opportunity to leave the network
if state = 1
Print("")
Print("Press Any Key To Close Network")
// if we are not currently connected, or trying to connect, give the user the opportunity to join the network
elseif state < 0
Print("")
Print("Press Any Key To Connect")
endif
// if any key has been released
if GetRawKeyReleased(GetRawLastKey())
// if we are currently connected
if state = 1
// disconnect from the network
CloseNetwork(networkId)
state = -1
// if we are not currently connected
elseif state < 0
// join the network
networkId = JoinNetwork("ZarkanEntertainment", "Client")
connectTime# = Timer()
state = 0
endif
endif
Print("Attempting to get data...")
//Attempt to get the message to see the card
GetNetworkMessage(networkId)
GetNetworkMessageInteger(card)
Print(card)
DeleteNetworkMessage(card)
Sync()
Loop
Return
Any help would be greatly appreciated!!!