Mirage Source http://miragesource.net/forums/ |
|
SOX instead of Winsock http://miragesource.net/forums/viewtopic.php?f=210&t=897 |
Page 1 of 2 |
Author: | William [ Wed Dec 20, 2006 8:11 pm ] |
Post subject: | SOX instead of Winsock |
Server Side: -Delete the mswinsock control from the project -Delete it from the control list too -Add the sox.ocx -Name it Socket <!--[if !supportEmptyParas]--> <!--[endif]--> frmServer.frm: <!--[if !supportEmptyParas]--> <!--[endif]--> delete or comment out the code you have for the old socket, Socket_Accept Socket_DataArrival Socket_Close <!--[if !supportEmptyParas]--> <!--[endif]--> Now make a new Socket_State sub(go to the topleft combo box thing in the code window and select socket) <!--[if !supportEmptyParas]--> <!--[endif]--> The state sub is called everytime the state of the socket changes 0 = close 1 = listening ‘server thing 2 = Connecting ‘Client thing 3 = Accepted ‘Server thing, Sox automatically accepts connections 4 = Connected ‘Client thing <!--[if !supportEmptyParas]--> Code: <!--[endif]--> <!--[endif]-->Private Sub Socket_State(ByVal Sox As Long, ByVal State As Long) If Sox <> 0 Then 'not the main listening socket Select Case State Case 3 Call AcceptConnection(Sox) Case 0 Call CloseSocket(Sox) End Select End If End Sub <!--[if !supportEmptyParas]--> That should make sense now. Now make a new DataArrival procedure. <!--[if !supportEmptyParas]--> <!--[endif]--> Private Sub Socket_DataArrival(ByVal Sox As Long, Data As Variant) <!--[if !supportEmptyParas]--> <!--[endif]--> End Sub <!--[if !supportEmptyParas]--> <!--[endif]--> Inside add If IsConnected(Sox) Then ‘sox is the internal array index, no more control arrays, but you should know that if you read the readme :P. Next add <!--[if !supportEmptyParas]--> <!--[endif]--> Call IncomingData(Sox, data) End If <!--[if !supportEmptyParas]--> <!--[endif]--> You will change the incomingdata sub later <!--[if !supportEmptyParas]--> <!--[endif]--> It should end up looking like this.. Code: Private Sub Socket_DataArrival(ByVal Sox As Long, Data As Variant) If IsConnected(Sox) Then Call IncomingData(Sox, Data) End If End Sub <!--[if !supportEmptyParas]--> <!--[endif]--> Private Sub Socket_Error(Sox As Long, Proc As String, Area As String, Code As Long, Abbr As String, Desc As String, DescEx As String) 'MsgBox "*** Error ***" & vbCrLf & vbTab & "Sox: " & Sox & vbCrLf & vbTab & "Proc: " & Proc & vbCrLf & vbTab & "Area: " & Area & vbCrLf & vbTab & "Code: " & Code & vbCrLf & vbTab & "Abbr: " & Abbr & vbCrLf & vbTab & "Desc: " & Desc & vbCrLf & vbTab & "DescEx: " & DescEx & vbCrLf & vbCrLf End Sub If you want you can add that, don’t need to, I commented it out on mine. <!--[if !supportEmptyParas]--> <!--[endif]--> Next: Incoming Data Sub Change the header to look like this Sub IncomingData(ByVal Index As Long, ByVal Data As Variant) <!--[if !supportEmptyParas]--> <!--[endif]--> Comment out or delete this: 'frmServer.Socket(Index).GetData Buffer, vbString, DataLength <!--[if !supportEmptyParas]--> <!--[endif]--> Add this, it converts the data to a string Buffer = StrConv(Data, vbUnicode) <!--[if !supportEmptyParas]--> <!--[endif]--> Scroll down in that sub and fine this: ' Check if elapsed time has passed Change the line below it to this: Code: Player(Index).DataBytes = Player(Index).DataBytes + UBound(Data) <!--[endif]--> Next go to the AcceptConnection sub <!--[if !supportEmptyParas]--> Code: <!--[endif]--> Sub AcceptConnection(ByVal Index As Long) Dim i As Long <!--[if !supportEmptyParas]--> <!--[endif]--> If (Index = 0) Then i = FindOpenPlayerSlot If i <> 0 Then ' Whoho, we can connect them Call SocketConnected(Index) <!--[if !supportEmptyParas]--> <!--[endif]--> Else frmServer.Socket.Close (Index) End If End If End Sub Make it like that <!--[if !supportEmptyParas]--> <!--[endif]--> In Sub CloseSocket Comment out where it closes the socket, kind of stupid making it close the socket since its getting called once the socket has closed. <!--[if !supportEmptyParas]--> <!--[endif]--> Change Function GetPlayerIP to Code: Function GetPlayerIP(ByVal Index As Long) As String GetPlayerIP = frmServer.Socket.RemoteHostIP(Index) End Function Find ' Get the listening socket ready to go Comment out both of the 2 lines under it which set the remotehost/port <!--[if !supportEmptyParas]--> <!--[endif]--> Comment/delete were it loads/unloads the sockets, you don’t need to do that anymore, its done internally. <!--[if !supportEmptyParas]--> <!--[endif]--> Find frmServer.Socket.Listen -Change it to frmServer.Socket.Listen frmServer.Socket.RemoteHostIP(0), Game_port (might need to change it to 127.0.0.1, I’m not sure) <!--[if !supportEmptyParas]--> <!--[endif]-->Go to Sub ServerLogic Get rid of that forloop which checks to see if it should close the socket <!--[if !supportEmptyParas]--> <!--[endif]--> Go to Sub UpdateCaption Change it how you want, figure it out. <!--[if !supportEmptyParas]--><!--[endif]--> Go to Function IsConnected Add Code: If Index >= frmServer.Socket.Count Then IsConnected = False Exit Function End If This is to avoid an error if it checks a socket which isn’t there. Code: If frmServer.Socket.State(Index) = 3 Then IsConnected = True Else IsConnected = False End If Now change the other if statement to this… <!--[if !supportEmptyParas]--> <!--[endif]--> Find .SendData (data here) Change it to frmserver.socket.sendstring i/index(depending where it is), data If you want to change this senddatatoall sub you can, you don’t have to though Go to sub senddatatoall Change it to frmServer.Socket.broadcast data |
Author: | Xlithan [ Wed Dec 20, 2006 9:17 pm ] |
Post subject: | |
SOX vs. IOCP? |
Author: | William [ Wed Dec 20, 2006 9:18 pm ] |
Post subject: | |
IOCP wins since SOX is pretty much like winsock, just easier to use if I got it right in my memory. |
Author: | Spodi [ Wed Dec 20, 2006 9:26 pm ] |
Post subject: | |
SOX is just a nice wrapper for the Winsock API. Theres a few hacks you want to do on the socket itself to get it prepped for a game engine, though. For example, it sends a 4-byte (long) overhead for every SEND command, which is pretty useless for a game server (integer would suffice), the default send/recv buffer comes at 8192 bytes (you'd be fine lowering that to around 512 bytes easily), etc. And just a heads up, you cant use IOCP with SOX I believe, so you can't have an IOCP server and SOX client, because of the additional header I mentioned earlier. |
Author: | Obsidian [ Wed Dec 20, 2006 10:10 pm ] |
Post subject: | |
Quote: And just a heads up, you cant use IOCP with SOX I believe, so you can't have an IOCP server and SOX client, because of the additional header I mentioned earlier.
'tis true [/code] |
Author: | TheRealDamien [ Thu Dec 21, 2006 12:00 am ] |
Post subject: | |
SOX in my personal opinion is a lot smoother/better... I have tried to add IOCP many times and guess what? Failure after failure... SOX is easy and in my personal opinion smoother and more stable. |
Author: | halla [ Thu Dec 21, 2006 1:15 am ] |
Post subject: | |
I added IOCP fine before but I never tested it with people getting on and so on... so I dont know from that end. |
Author: | TheRealDamien [ Fri Dec 22, 2006 11:35 am ] |
Post subject: | |
Lol trust me... Its a nightmare all on its own. |
Author: | Obsidian [ Fri Dec 22, 2006 6:59 pm ] |
Post subject: | |
I've never had a problem with IOCP... this is a bit easier to add though... but i'm not sure how they compare as far as handling individual players.... but they're both probably far superior to the winsock control... |
Author: | SoccerPeter [ Wed Jan 03, 2007 2:30 am ] |
Post subject: | |
Don't take my word for it, because I don't know anything about SOX really, but someone told me a while ago that it can handle 6000 players easily provided they are on a good enough server machine. Is this true? |
Author: | grimsk8ter11 [ Wed Jan 03, 2007 2:33 am ] |
Post subject: | |
SOX is better ebcause its nicer. the hacks make the capabilities better to. it also supports pre-NT machines, IOCP does not. |
Author: | Misunderstood [ Wed Jan 03, 2007 3:14 am ] |
Post subject: | |
If anyone has a working sox client, please send it to me, I want to see if it works. I've been having trouble running MS via wine on linux, it works up to initializing TCP settings, which makes me think its a problem with winsock, I'm just curious if a sox client would work. |
Author: | Spodi [ Wed Jan 03, 2007 6:47 am ] |
Post subject: | |
SOX is built to be almost exactly like Winsock but easier - learn the controls and give a try. |
Author: | Bakekitsune [ Sun Feb 25, 2007 9:26 am ] |
Post subject: | |
hacks? also apparently you cant send binarydata with sox because of null. and were can you download the ocx? edit: dont worry i think im already using iocp lol |
Author: | Boo [ Thu Apr 12, 2007 12:15 am ] |
Post subject: | |
I was talking to nemesis and this is what he told me. On his testing when he used IOCP it used 70% of his CPU and when u used Sox it used only 30%. From this i concluded self explanitory that it'll be way faster to use Sox over IOCP unless your using a 3+ Dual Processor thats badass lol |
Author: | Spodi [ Thu Apr 12, 2007 2:50 am ] |
Post subject: | |
Bakekitsune wrote: hacks? also apparently you cant send binarydata with sox because of null. and were can you download the ocx? edit: dont worry i think im already using iocp lol SOX handles data as variants by default, just like the winsock control. You can send as string or byte arrays. Quote: On his testing when he used IOCP it used 70% of his CPU and when u used Sox it used only 30%.
SOX itself is pretty bloated as-is, and not really made well for games. You should try GOREsock from vbGORE - its a modified version of SOX directed towards faster handling. It takes out a lot of the overhead SOX has, like that extra 4 byte packet header added with every SendData call, plus easier handling for encrypting/decrypting packets. |
Author: | Boo [ Thu Apr 12, 2007 3:40 am ] |
Post subject: | |
well make a good copy/paste tutorial on how to add it into Mirage and we're all good Spodi |
Author: | Spodi [ Thu Apr 12, 2007 4:05 am ] |
Post subject: | |
Well it should be the same as adding SOX, but instead of a control its a module. |
Author: | Tony [ Thu Apr 12, 2007 4:09 am ] |
Post subject: | |
Why did you name your engine vbgore? Isn't gore an object and action as well? |
Author: | Nexarcon [ Thu Apr 12, 2007 4:42 am ] |
Post subject: | |
Kuja wrote: Why did you name your engine vbgore?
Isn't gore an object and action as well? It stands for something Visual Basic Graphical(?) Online RPG Engine |
Author: | Spodi [ Thu Apr 12, 2007 7:37 am ] |
Post subject: | |
Nexarcon wrote: Kuja wrote: Why did you name your engine vbgore? Isn't gore an object and action as well? It stands for something Visual Basic Graphical(?) Online RPG Engine Exactly. A huge part of it was that I was trying to find something with very few results to Google so I can track the engine easier. You can type in "vbGORE" into google and most all results are towards my vbGORE. If you try that with Mirage, or Elysium... well, we all know. |
Author: | Boo [ Thu Apr 12, 2007 10:59 pm ] |
Post subject: | |
thats also why I used Eloric But if you can PM me info on how to add that socket i'll be happy spodi |
Page 1 of 2 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |