Ive never made a p2p style battle system before and Im the type of person i learn by seeing the completed code vs. trial error. The MSDN had something that seemed to be on the right track but im not sure how to code it. The Network button click action is were I think most of this code will take place. When you click on the network button, I want it to popup a box requesting the ip to link to for battle. MSDN suggests this for networking. This is how to send text but I need it to send something else:
SharedSub Connect(ByVal server As[String], ByVal message As[String]
)
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
'Changed to port 80 to avoid port forwarding
Dim port AsInt32
= 80
Dim client AsNewTcpClient
(server, port)
' Translate the passed message into ASCII and store it as a Byte array.
Dim data As[Byte]() = System.Text.Encoding
.ASCII.GetBytes(message)
' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream AsNetworkStream
= client.GetStream()
' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)
Console.WriteLine("Sent: {0}"
, message)
' Receive the TcpServer.response.
' Buffer to store the response bytes.
data =
New[Byte]
(256) {}
' String to store the response ASCII representation.
Dim responseData As[String] = [String]
.Empty
' Read the first batch of the TcpServer response bytes.
Dim bytes AsInt32
= stream.Read(data, 0, data.Length)
responseData = System.Text.
Encoding
.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}"
, responseData)
' Close everything.
stream.Close()
client.Close()
Catch e As
ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}"
, e)
Catch e As
SocketException
Console.WriteLine("SocketException: {0}"
, e)
End
Try
Console.WriteLine(ControlChars.Cr + " Press Enter to continue..."
)
Console
.Read()
EndSub'Connect
I need it to connect to the other person and then contenue to update each others health information and military counts etc. until someone dies or retreats. I use a class called "storage" to store all the global information. So basicly we need to make calls to the storage class across the network. I can post more code if someone wants to try to help. Thanks
Hm, just a formal note:
It's quite difficult to read your code when it's just posted inside the forum. It would be much easier to read if you'd post it on some kind of pastebin with syntax highlighting, such as pastebin.com.
EDIT:
Plus, you might want to consider asking your questions on #programming or #vb on freenode.
I'd certainly echo to at least some xtent the previous poster's response.
Your code is very hard to read when it's not properly formatted.
Further, the title of this thread refers to a battle-system but it would appear your problem is more with establishing (and maintaining) a network connection between two computers using VB. If your problem is actually implementing the logic of a battle-system then I can likely help. If your problem is network issues in VB then I probably can't (I haven't used VB of derivatives in probably 10 years).
Your snippet of code is also rather light on context. The code you have there seems to qssume a connection has already been made. How was it made? Are you sure it's been successfully made? Some information on the overall strcuring you're using for your program would be handy in at least establishing how you can work out whether the 'bug' is in the code you pasted or in some other routine which you're assuming to be working correctly.
I made the code lol Im using it in a game. I think I left out some of it but it was not needed. Just was wondering how to make a network streamed battle system. I assume I need to stream the players health and damage to each other. So just looking for a snippet sample. Thank you in advance.