Raised This Month: $ Target: $400
 0% 

Multi-Thread in sockets! Help please!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
johnally
Member
Join Date: May 2011
Location: Mauritius
Old 06-17-2011 , 11:04   Re: Multi-Thread in sockets! Help please!
Reply With Quote #1

Yep.. I have the socket_hz method commented in my codings .. I tried it and still block server and sometimes would require bigger timeout to see changes.

I inspired myself from sXe-injected:
PHP Code:
public client_putinserver(id
{
        
connect_web(id); // The Auth process starts here! <<<<<<---------<<<<<<<
}

public 
send_and_read(idconstring[512], ctype//Where data sent on socket! ctype = 1 or 0 .. 1 means it is client_auth.. and 0.. normal blocking socket reading!
{
    new 
parames[2]
    
parames[0] = id
    write_web
(constring)  // socket_send :)
    //socket_close(g_sckweb) // socket_hz function
    
if (ctype == 1) {
        
parames[1] = // timeout value
        
set_task(2.0"read_web"202parames2"b"// repeated infinite call!
    
} else {
        
parames[1] = 10000000 // timeout value
        
read_web(parames// normal call!
    
}

connect_web function has same structure as in webservers and sockets example except I used the function above to combine "send and read"..
parames[1] holds timeout value for socket_change in read_web function.
set_task is set as "b" infinite.

I use the "remove_task(202)" in the if statement (socket_change)..

As such users can be authenticated and not cause server to freeze.. Hail to sXe-injected!

The main change was:
PHP Code:
if (socket_change(g_sckwebparames[1])){
      
remove_task(202//Remove the infinite task!
      // Do something, socket changed :D
} else {
      
// No change in socket!

socket_change made server wait for too long with higher timeouts. Setting a task at a 1-5s interval and a timeout of 1, would ensure that repetitive regular checking of socket would be done while server is not forced to wait for the change to happen.

in other words, socket_change(socket, timeout) will make the server waits for a change in socket until it reaches timeout or return true for an actual change!


Cheers,
__________________
No allowed!


Last edited by johnally; 06-17-2011 at 11:21.
johnally is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode