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-15-2011 , 13:22   Multi-Thread in sockets! Help please!
Reply With Quote #1

Hey guys, you've been a lot of help to me so far. Thanks to you all.

I was using the webservers and sockets example but noticed that whenever the socket would be listening or waiting for some response, the whole server went gaga(freezed until response received.)

My solution was to try get receiving of data happens in another thread. But how to do that? I did some research and it only came with 'SQLx multi threading'.

Anyone can help me out or propose a better way?.... BIG thanks!
__________________
No allowed!


Last edited by johnally; 06-15-2011 at 14:28.
johnally is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 06-15-2011 , 20:19   Re: Multi-Thread in sockets! Help please!
Reply With Quote #2

would be very usefull to create a Threaded Sockets Module.

Too bad that i don't have the necesary knowledge to acomplish that.
DjOptimuS is offline
johnally
Member
Join Date: May 2011
Location: Mauritius
Old 06-16-2011 , 10:33   Re: Multi-Thread in sockets! Help please!
Reply With Quote #3

@DjOptimuS me too..

Well .. I hack'd my way through.. and guess that the most appropriate thing is "not to use socket at all" or "use set_task and make sure data received via sockets ain't event dependent ><" ..
I think sXe-injected use set_task on clientputinserver I'll do same!!

If still, someones found a better way.. let us know.
__________________
No allowed!

johnally is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 06-16-2011 , 16:49   Re: Multi-Thread in sockets! Help please!
Reply With Quote #4

socket_hz Tutorial by Hackinzer
__________________
okay
ARES[ro] is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 06-16-2011 , 22:33   Re: Multi-Thread in sockets! Help please!
Reply With Quote #5

Sockets_hz helps on listening, but it blocks the server too. I already tested it.

The function socket_unblock isn't working propely, and, besides, you read the code samples ? You must set an infinite loop task, from short time to short time, like 0.3 seconds, or 0.1 on the sample you gave. Isn't ok.

I use sockets to call a HLTV process, using a HLTV code sample finded here on the forums, i adapted the code to Sockets_HZ, but, because of the set task, sometimes i didn't received the challenge id from the HLTV, so Sockets_HZ isn't a solution, a Threaded Sockets Module IS the solution.
DjOptimuS is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 06-16-2011 , 23:41   Re: Multi-Thread in sockets! Help please!
Reply With Quote #6

Well, take a look at Hackinzer's mIRC server!
__________________
okay
ARES[ro] is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 06-17-2011 , 01:02   Re: Multi-Thread in sockets! Help please!
Reply With Quote #7

i see that you are from romania, i am from romania too, and i used to work for the biggest hosting provider from romania, and i know that almost all of the cs servers owner, don't understand what socket mean (at least from romania).

If you have the server hosted in Romania, for example a WAR server, and you want to use HLTV on it, but you have the HLTV located in the USA for example, be sure that the HLTV calling functions will hang the server. If you don't know what do you say, don't say it.
DjOptimuS is offline
johnally
Member
Join Date: May 2011
Location: Mauritius
Old 06-17-2011 , 11:04   Re: Multi-Thread in sockets! Help please!
Reply With Quote #8

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
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 06-17-2011 , 12:04   Re: Multi-Thread in sockets! Help please!
Reply With Quote #9

sometimes the sockets returns nothing just because the standard infinite loop is too fast, for example 0.1 or 0.2 set_task to listen the socket.

The Sockets_HZ ideea is good, but only if the socket you need to call is relatively close to your server, or maybe on the same server, but in this case, the standard socket will work, because everything is fast. But the problem appears when you need to call something via socket that have ping over 40-50 ms between them
DjOptimuS is offline
johnally
Member
Join Date: May 2011
Location: Mauritius
Old 06-17-2011 , 12:13   Re: Multi-Thread in sockets! Help please!
Reply With Quote #10

Yes.. the issue comes if it's over 40-50ms latency between the two servers
__________________
No allowed!

johnally is offline
Reply


Thread Tools
Display Modes

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