![]() |
Alternative IOCP Tutorial - Printable Version +- Mirage Engine (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: Alternative IOCP Tutorial (/showthread.php?tid=805) |
Alternative IOCP Tutorial - Xlithan - 08-03-2007 This version of the tutorial was released on the ED forums, but this is the one I used to add to Mirage Source which seemed to work first time. Again, credit goes to Verrigan for this, and Aranshada for writing the tutorial. This tutorial will NOT work with Windows 95/98/ME Servers In order to do this tut, you will need to download this .dll file and register it. THIS IS A NECESSITY FOR THIS TUTORIAL!!! http://aranshada.hopto.org/Elysium/Downloads/COMSocketServer.dll -=: Server-Side :=- First thing's first, go to Project > References... and scroll down until you find JetByte Socket Server 1.0 Type Library. Check the box beside it and click OK. Download Sonires classes, these are guaranteed to work in MSE (Tested myself). http://www.freewebs.com/msebuild1/classes.rar To add these to your server project after downloading them, go to Project > Add Class Module, and click the Existing tab, and select the a module that you downloaded. Repeat this until you have all three class modules added to your project. Now that we have the class modules out of the way, we have to go through the rest of the server and change some stuff. So, what do you think we'll need to change first? We'll need to change the methods for creating the sockets, destroying the sockets, and anything that checks a socket for a connection. In modServerTCP, add these declarations at the top. Code: ' Our GameServer and Sockets objects for the TCP interaction In modGeneral, find Sub InitServer. Find: Code: ' Get the listening socket ready to go Either way, add this below it: Code: Set GameServer = New clsServer Just below that you'll see this: Code: ' Init all the player sockets Code: Call GameServer.Sockets.Add(CStr(i)) Code: ' Init all the player sockets Keep looking in that same sub until you find this: Code: ' Start listening Code: GameServer.StartListening Now, still in modGeneral, find Sub DestroyServer. Inside of Sub DestroyServer, find this: Code: For i = 1 To MAX_PLAYERS Code: For i = 1 To MAX_PLAYERS Now go to Sub UpdateCaption in modServerTCP. Change the whole sub to this: Code: Sub UpdateCaption() What's our next target? Sub SendDataTo. It is also located in modServerTCP. Change the entire thing to this: Code: Sub SendDataTo(ByVal index As Long, ByVal Data As String) You can see where I simply commented out the old code and added the new above it. This also shows you the method used for sending a packet. So... we've changed how it loads the object, destroys it, and how it sends data. What's next? Find Function IsConnected in modServerTCP. Change the whole function to this: Code: Function IsConnected(ByVal index As Long) As Boolean Now that we can't exactly check the socket's state against VB's Winsock Constants, we can simply check to see if a certain socket Is Nothing. If it Is Nothing, then it hasn't been initialized, meaning that there isn't a live connection, so we return false. Otherwise, it's true. Now we'll tackle all of the subs that are fired when a connection is received or closed. In modServerTCP, find Sub AcceptConnection. Change the whole thing to this: Code: Sub AcceptConnection(Socket As JBSOCKETSERVERLib.ISocket) Find Sub CloseSocket in the same module. Change the whole sub to this: Code: Sub CloseSocket(ByVal index As Long) Now to deal with IncomingData. Also in modServerTCP, find Sub IncomingData. Change the whole sub to this: Code: Sub IncomingData(Socket As JBSOCKETSERVERLib.ISocket, Data As JBSOCKETSERVERLib.IData) There's not really any need to check for this anymore since I don't think the socket state COULD be like that with COMSocketServer. Now, go to frmServer. Find these subs: Code: Private Sub Socket_Close(index As Integer) I believe that's all there is for the Server-Side of things. On to the client! -=: Client-Side :=- Don't worry, we won't be here long. In the client, go to modClientTCP and find Sub SendData. Change the whole thing to this: Code: Sub SendData(ByVal data As String) Optionally, you might also want to set the MAX_PLAYERS in your Data.ini to something much higher. It's less stress on the server now since it doesn't have to load up a new Winsock object for every connection. Now it just adds a new object to a collection. I've seen some servers with IOCP that had MAX_PLAYERS set at 500. I've seen another one with it set at 1000. That's really just personal preference, though. Now, I'm pretty sure I didn't miss anything. If anyone gets any errors after trying this tut, copy/paste the section of code that is highlighted as well as the surrounding code, and I'll see if there's something that I forgot to put in the tut. Credit for the code in this tutorial goes to Dave's Valkorian Engine source because I looked at all of the code in there to find out how to do this. Some credit also goes to Pingu for requesting this tutorial in the first place. - Joost - 08-03-2007 Due to people trying to 'fake' Elysium, you can't repost tutorials from ES. We should have a thread about that somewhere. Anyway, since this is MS, I don't really care, I'll check with Aran if it's okay with him too, and if not, I'll update this post. - Xlithan - 08-03-2007 Oh ok. I didn't know. My view on open source programming and code sharing is slightly different than others then. - Godlord - 08-03-2007 And there are also some Run-time errors on this so far as I know. RTE: 91 and another one which I don't remember. - William - 08-03-2007 Quote:Due to people trying to 'fake' Elysium, you can't repost tutorials from ESThe tutorial was originaly posted on MS forum, no more than right to share a modified here. - Joost - 08-03-2007 GameBoy Wrote:Oh ok. I didn't know. My view on open source programming and code sharing is slightly different than others then. I agree mostly. The problem was, at one point there even was an 'Elysium Underground' stealing all our tutorials and, basicly, everything. That kinda shit pisses me off. I have totally no problems with it being at MS though. . - Godlord - 08-03-2007 Verrigan it was tried with the .DLL registered. It is an error in the tutorial I don't know why it shows up but the tutorial can give some problems. - Xlithan - 08-03-2007 Paste the code to me. I know I had to modify something myself, but it wasn't major. Did you add the DLL to the references? - Sephiroth187 - 13-03-2007 just make sure you make a proper installation for clients to use this. Perhaps in the initialization stage of the program; If a error comes up-; Code: Sub Main() It should hopefully work. This is also assuming the user is "innocent" with expected computer settings. - Coke - 13-03-2007 What pisses me off is elysium was made from konfuze, which wouldnt of existed without this community; so if people want to share tutorials i think they bloody well can =P - Joost - 13-03-2007 Fox Wrote:What pisses me off is elysium was made from konfuze, which wouldnt of existed without this community; so if people want to share tutorials i think they bloody well can =PWhat pisses me off is that MS was made in Visual Basic, so Microsoft should have all rights to MS. Your logic is almost as good as a drunk man's logics. Almost. - Coke - 13-03-2007 William Wrote:Quote:Due to people trying to 'fake' Elysium, you can't repost tutorials from ESThe tutorial was originaly posted on MS forum, no more than right to share a modified here. - Xlithan - 13-03-2007 No Joost it doesn't work like that. That's like saying my music that I created belongs to Steinberg because I recorded it with their software. There are parts of Elysium which are still original parts of Mirage Source. - Joost - 13-03-2007 Fox Wrote:And William is wrong. Aran ripped this tutorial from one of Verrigan's sources. So you can go around quoting people, but generally speaking, I'm correct more often than the average person.William Wrote:Quote:Due to people trying to 'fake' Elysium, you can't repost tutorials from ESThe tutorial was originaly posted on MS forum, no more than right to share a modified here. @GameBoy, even if some parts are the same, MS has no license, so Fox can't go around telling me I have to do things because it was made from Mirage or konfuze, or whatever. - Coke - 13-03-2007 Verrigan is considered a very valued part of the community, i am sure he would want adaptations on his work shared. - Joost - 13-03-2007 Yes, and you don't see me complaining, do you? I just stated that normally, normally people can't repost tuts from ES. - Xlithan - 13-03-2007 CodeFixer for the win 8) - Sephiroth187 - 14-03-2007 Verrigan Wrote:You should always ensure that libraries are registered at installation time. Other things to consider are: Ah dude I crave criticism, I get disappointed if no one criticises, thanks for it. Dont worry if I get offended, I will only get offended if I generally think its an unjust comment, which yours was definantly not - even if I do get offended I dont flame, its never my nature. I will tell you what I thought of the comment but thats about it. Yes, I did realise I should of made the user aware that I will also be registering, but I was assuming that if the file was being copied into a folder labeled such as "system32" the user would generally think that it is important. But this is easily changed :p Ah I do nesting generally all the time. This was a quick example. But I will consider it for writing other examples, kinda my first time sharing knowledge 8) - Sephiroth187 - 15-03-2007 question : This IOCP thing. Does it require Winsock to work. I've been trying to mess around with it, I'm confused how to get it to connect. Anyone have any good tutorial references? I will continue to mess about with it regardless... It seems interesting. *edit* Ah I managed to get it working dont worry |