Author Topic: SocketCore  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
SocketCore
« on: October 07, 2009, 12:13:28 pm »
Script Name: SocketCore
Script Description SocketCore to handle socket based connections.
Author: Dual
Compile Test: Failed. Error Detected.
Core Version: 3.0
Hosted by: Soldat Central - http://soldatcentral.com/

Usage:

function InitSocket(const IP: string; const Port: integer; const ReconTime: word; const Retries: integer): integer;

Initializes a new socket and connects it to the given IP & Port.
ReconTime specifies a time in milliseconds to wait before trying to reconnect if the remote host disconnected.
Set Retries to -1 for no limit of reconnect attempts.

The function returns an integer value which will be your handle for OnPacketReceived, WriteLnSocket and OnDisconnect.
In case the return value is -1, the socket failed to connect to the remote host and the socket instance will be destroyed.



procedure OnPacketReceived(const Handle: integer; const Packet: string);

Use this procedure for any data parsing events. It will be called whenever a new packet has been received.
Handle will be the socket which received the packet.



function WriteLnSocket(const Handle: integer; const Packet: string): boolean;

Sends a line to the remote host. If the line has been sent, the function will return true.



procedure OnDisconnect(const Handle: integer);

This procedure will be called whenever a remote host disconnected.
Handle will be the disconnected socket.


I especially want to say thanks to dnmr` for helping and improving the script.
If you find any bugs, let me know. Last but not least make sure you have turned off the safe mode before running this script.



(Size 1018 B)
- http://soldatcentral.com/index.php?page=script&f=150 -


** Script hosted by Soldat Central! Please visit the author's script page and Rate this script **
« Last Edit: November 16, 2009, 12:07:10 pm by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Stable threaded sockets anyone?
« Reply #1 on: October 07, 2009, 12:21:21 pm »
well, from what i understood, this script communicates with a server set up at Curry's machine via sockets. It uses threads and doesn't crash. It was a test for a bigger project, so i dont think the server will be released any time soon, but you should be able to set up something simple if you want to test it on your own (without using the demo server at 91.9.159.204).

Here's some basic stuff on the parameters you'll want to modify (if you cba reading it from the script) - the stuff on line 109

IP, Port - keep what's provided to use the test server
ReconTime - time in milliseconds to wait before trying to reconnect if the server disconnects
Retries - time to try reconnecting. -1 for no limit


Can't think of anything else to add, this was just a simple test =) Although we did find it weird that it was pretty stable...

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Stable threaded sockets anyone?
« Reply #2 on: October 07, 2009, 12:56:26 pm »
I've never had many issues in regards to threads (never actually for sockets, its always the threads causing the issues) - occasional random shutoff, or even errors, or both; only time I really had issues was when I had many many threads going (like a new one made every second, lol) which ended up with many many errors, which is understandable to some extent.
Also its hard sometimes to tell if Sleep or threads are the issue - afaik its only the fact that it is in a thread, so I don't think Sleep will give anybody problems. (A loop to delay time would probably be worse (and a HORRIBLE idea)).
EDIT: I looked and noticed that there's nothing in regards to all the threads just completely dieing randomly, which could be a problem (as I have had that happen before)..
« Last Edit: October 07, 2009, 01:08:37 pm by DorkeyDear »

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Stable threaded sockets anyone?
« Reply #3 on: October 08, 2009, 01:08:29 pm »
Well, forgot about Soldat sockets.
tk and me did some tests with them and they didn't work properly.
Some pcs can handle threads well, while others fail.

I'm sorry if I gave some people hope that we can use stable sockets in the current dedicated server realease.
Let's wait for the new server and hope EnEsCe will have implemented stable threading :P
Soldat Global Account System: #soldat.sgas @ quakenet

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: SocketCore
« Reply #4 on: November 16, 2009, 12:00:07 pm »
Since threading seems to be more reliable in the latest dedicated server, I updated the script to make it compatible with 2.7.0.
Furthermore I added some lines on how to use the script properly. See the first post for more information.

Please note that the script doesn't compile with older dedicated server versions than 2.7.0 and since EnEsCe hasn't updated soldatcentral to support the latest dedicated server with ScriptCore 3.0, the script compilation fails.
I also suggest to only open one socket connection at once, because a couple of threads will cut down your server stability.
Soldat Global Account System: #soldat.sgas @ quakenet