The server would then have to read it, in the same order it was written. The packet is a byte array (byte) holding the 3 integers added in the code above. The packet and packet number are sent to the receiving end, and the receiving end uses the packet number to know how to interpret the data. So I am still unsure of the exact usage method one e, lol - So am I right that you do something like prepare a packet with several variables to be sent over the network, and then call SendPacketToServer() when you have piled up some variables for a single frame or something?Ĭlick to expand.So in this system, a "packet" is a collection of data, with a number attached to it (a packet number). This would help me understand tremendously, haha. I think the project could benefit from maybe a github so others can contribute changes, and an example scene showcasing a few things going on (maybe just two cubes with synced movement while sending a few random variables every few seconds, and displaying them on a gui so you can visually see they are matching up across all clients/server). I hope that all makes sense and is logical haha. I guess what I am asking is - if I wanted to use an RPC to send several things (like maybe a position of something, and a few random bools or perhaps some floats.) I would send some parameters through a RPC method to the clients, and instead with this I would just leave that all up to packetwriter? Like you just do maybe AddInt(ImportantInteger) then AddFloat(UpdatedFloat) and finally SendPacketToServer() to have the actual RPC take place - which I guess is handing byte arrays as parameters between the RPC's? ![]() This is ideal for any project, and almost necessary if you have advanced networking needs as in an mmorpg.Ĭlick to expand.So I am still unsure of the exact usage method one e, lol - So am I right that you do something like prepare a packet with several variables to be sent over the network, and then call SendPacketToServer() when you have piled up some variables for a single frame or something? It is just as fast as unity's rpc calls, but there's NO HASSLE! It's so easy to send data back and forth, and you don't have to create constant RPC methods in the server and client. It's also so easy to just say, buildpacket,addstring,sendpacket. An MMORPG requires a LOT of data sending back and forth, to tons of players, and this system can handle it, despite how basic it really is. I use this system in my MMORPG, and it can be used for really any type of data transferring. Put a lot of work into making this thread. If you have any questions/suggestions please let me know. So that's everything you need! Of course make sure you connect to the server using the network class before sending any packets. The byte array is sent over the RPC function, and the packet reader interprets the byte array and gives you the variables. The packetwriter will convert your variables into byte arrays and combine them all into one byte array. So how does this all work? Let me explain. just PM me/post a reply quoting me and I'll tell you how to. If you want to send other types of variables that aren't already in the code, feel free to add some more. To send floats/strings/etc, just look at the PacketWriter class for the functions. So we know how to send packets back and forth now. Here are the two classes: (MAKE SURE TO CHANGE YOUR_NETWORK_VIEW TO A REFERENCE TO YOUR NETWORK VIEW COMPONENT IN PACKETWRITER.CS) Self explanatory, one class builds a packet and the other takes the received packet apart! Now this is a very efficient system, but due to the rpc function not being able to accept byte as a parameter, the data being sent back and forth is slightly larger than if it did accept byte parameters. All the data is sent through those RPC functions and understood by the receiver. That's it! That's the only real Unity network functions that are used. I use a total of 2 RPC Functions, 1 on the server, 1 on the client, and they are both identical in ways they work. I have a server and a client (in my case, an authoritative server) and they need to communicate back and forth, a large variety of things. Feel free to discuss this system with me too. I don't see why I shouldn't share and help out other people. I used this for my mmorpg, and think others might find some use out of. I needed a networking system for my game, so I created one for myself that actually uses only Unity. It's great for a first person shooter type game, but from what I've seen most people use a 3rd party network server that is entirely outside of unity. So I noticed Unity's network system is a bit. ENSURE YOU SET THE PLAYER SETTINGS TO RUN IN BACKGROUND Then run the client code in the editor and watch the console. Build the server scene into an exe, and run it. Simply change the IP & Port in the server & client scripts and try it out. Due to the requests, I have created a DEMO project for you guys.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |