Raised This Month: $ Target: $400
 0% 

socket_extention


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ramono
Veteran Member
Join Date: Nov 2005
Location: Netherlands
Old 08-23-2007 , 18:16   Re: socket_extention
Reply With Quote #1

It mostly works. only 1 bug..

socket_accept(socket) locks the server untill a client connects. after the client is accapted and you call socket_accept(socket) again it locks again...

Gj on the plugin so far, its great :d


Edit: i actualy got IE to connect with it and show a simple html file
This can work out great, like remote acces control, Fast download ( wich im buzy with now )
__________________
Um, hi.

Last edited by Ramono; 08-23-2007 at 18:31.
Ramono is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-24-2007 , 01:19   Re: socket_extention
Reply With Quote #2

Quote:
Originally Posted by Ramono View Post
Edit: i actualy got IE to connect with it and show a simple html file
Can you show that little plugin xP, i'm interested too! Thanks.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Ramono
Veteran Member
Join Date: Nov 2005
Location: Netherlands
Old 08-24-2007 , 05:04   Re: socket_extention
Reply With Quote #3

Quote:
Originally Posted by Alka View Post
Can you show that little plugin xP, i'm interested too! Thanks.
I kinda overwritten it. but here is the basic for socket listen

Code:
#include <amxmodx> #include <sockets_hz> #define MAXDOWNLOADS 15 new downloadsockets[MAXDOWNLOADS+1] new sckFastDownload public plugin_init() {     register_plugin("S_HZTEST", "1.0", "NL)Ramon(NL")         if (cvar_exists("amx_FastDownload_socket")) {         sckFastDownload = get_cvar_num("amx_FastDownload_socket")     }     else{         register_cvar("amx_FastDownload_socket", "0", FCVAR_PROTECTED&FCVAR_UNLOGGED)         connect_FastDownload()     }     register_srvcmd("acceptcall","read_FastDownload")     set_task(0.1,"read_lol",0,"",0,"b") } public connect_FastDownload() {     new error = 0     sckFastDownload = socket_listen("10.0.0.127",80,SOCKET_TCP,error)     if (sckFastDownload > 0) {         //read_FastDownload() LOCK THE SERVER UNTIL FIXED     }     else {         switch (error) {             case 1: { server_print("/* Error creating socket */")             }             case 2: { server_print("/* Could not resolve hostname */")             }             case 3: { server_print("/* Could not connect to given host:port */")             }         }     } } public read_FastDownload() {     static newClient     newClient = socket_accept(sckFastDownload)     if(newClient) {         new i         while(i<MAXDOWNLOADS) {             if(!downloadsockets[i]) {                 server_print("Connect")                 downloadsockets[i] = newClient                 //nextaccept() LOCKS THE SERVER UNTIL XIF                 return PLUGIN_CONTINUE             }             ++i         }         log_amx("[FASTDL] MAX SIMILAR DOWNLOADS REACHED, CLIENT CONNECTION REFUSED")     }     //nextaccept()  LOCKS THE SERVER UNTIL FIX     return PLUGIN_CONTINUE } public nextaccept() {     if (sckFastDownload != 0)         set_task(10.0, "read_FastDownload") } stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood     new nIdx = 0, l = strlen(p_szInput)     new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))     while( (nLen < l) && (++nIdx < p_nMax) )         nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))     return nIdx } public read_lol() {     new i     while(i<MAXDOWNLOADS) {         if(downloadsockets[i]) {             if (socket_change(downloadsockets[i], 100)) {                 new buf[512], lines[10][100], count = 0                 socket_recv(downloadsockets[i], buf, 511)                 count = ExplodeString(lines, 10, 99, buf, 13)                 for(new i=0;i<count;i++) {                     server_print(lines[i])                 }                 connect(lines,i)             }         }         ++i     } } public write_lol(text[512],dlnum) {     socket_send(downloadsockets[dlnum], text, 511) } public disconnect_lol(dlnum) {     downloadsockets[dlnum] = 0 } public connect(lines[10][100],socketclientarray) {     // do ya stuff here }

acceptcall in server console will check if there is a client connecting. it will lock the server until somone does, so i didnt make it go automaticly yet.

It will listen on the default http port. 80
if you write acceptcall in console and make IE try to connect it it will show you what IE has send. not more cause i overwriten the small html thingy...

Code:
to make it work send somthing like this back
HTTP/1.0 200 OK
Date: Thu, 08 Apr 2004 18:24:33 GMT
Server: Apache/1.3.29 (Unix) PHP/4.3.4
X-Powered-By: PHP/4.3.4
Content-Language: nl
Content-Type: text/html; charset=iso-8859-1
X-Cache: MISS from wikipedia.org
Connection: close
Content Type: TEXT/HTML
Content Length: 3'127 bytes (received)
De HTML code HERE
http://en.wikipedia.org/wiki/Hyperte...nsfer_Protocol

It will show what the client send you in server_print
__________________
Um, hi.

Last edited by Ramono; 08-24-2007 at 05:10.
Ramono 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 07:53.


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