AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: Sockets_hz ( listenning + nonblocking ) ... working :) (https://forums.alliedmods.net/showthread.php?t=60026)

Alka 08-20-2009 15:19

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
What's wrong with tasks ? They'r needed for TCP connection and hackziner is a bit busy until september or something like that.

joaquimandrade 11-12-2009 10:08

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
A folk remembered me that I modified this module for use in a plugin of mine. The difference is that since socket_open does one operation in blocking mode it still can hang the server. So, this version brings socket_open_non_blocking so all the operations can be done in non blocking mode. Source, win and linux version in the zip file here http://forums.alliedmods.net/showthread.php?t=99516

(Confirmed by hackziner)

AntiBots 11-18-2009 18:49

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by Exolent[jNr] (Post 789707)
I would like to retrieve the IP that is connecting to the socket.

I dont test, buts I know that is like this.... hz then update it....

PHP Code:

// native socket_accept(_socket, &port, ip[], iplen);
static cell AMX_NATIVE_CALL socket_accept(AMX *amxcell *params)  /* 2 param */
{
    
int NewClient;
    
struct sockaddr_in cin
    
int sinsize;
    
int socket params[1];
    
NewClient accept(socket, (struct sockaddr*)&cin, (socklen_t*)&sinsize); //hz

    
if ( NewClient <)
       return -
1;

    
// By Reymon
    
MF_SetAmxString(amxparams[3], inet_ntoa(cin.sin_addr) , params[4]);
    
cell *port MF_GetAmxAddr(amxparams[2]);
    
port ntohs(cin.sin_port);
    
//

    
return NewClient;



AntiBots 11-22-2009 18:52

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Any want a update of this?? I am working and I have time to add things if someone need it.

like a hacer to get host name. and stuff like that.

PM me or write me here!!

Good Bye!!

Dygear 01-17-2010 17:59

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by AntiBots (Post 996374)
Any want a update of this?? I am working and I have time to add things if someone need it.

like a hacer to get host name. and stuff like that.

PM me or write me here!!

Good Bye!!

Yeah, that would be awesome!

Code:

socket_listenfw(szAddress, iPort, SOCKET_TCP, iError, 'fwFunction');
This should also set the plugin to an automatic non-blocking mode by calling that function.

Quote:

Originally Posted by Bugsy (Post 793547)
A forward for incoming data would be nice so it can be handled as it arrives. This would eliminate the need for set_tasks\loops for socket_change checks for incoming data.

Yeah, I'm thinking about posting an enhancement request to move all of these functions into the core of AMX Mod X, as they really should of been there in the first place.

Quote:

Originally Posted by hackziner (Post 524901)
public auto_accept_reply() {
new this_chaussette;

if((this_chaussette=socket_accept(listening_s ocket))<0)
{
server_print("No pending connection")
}
else
{
new cmd[1024]
server_print("Accept/send/close")
format(cmd,1024,"Something to send")
socket_send(this_chaussette,cmd,1024)
socket_close(this_chaussette)
}

}
[/php]

Your sending this to a HTTPd server? Should you not be sending a HTTP Header?

Code:
        new cmd[1024]         server_print("Accept/send/close")         format(cmd,1024,"Something to send")         socket_send(this_chaussette,cmd,1024)         socket_close(this_chaussette)

I changed around your example, here's the code (I have no idea if this works by the way. but it does compile, so that's a plus).

Code:
#include <amxmodx> #include <sockets_hz> new g_iSocket, szAddress[] = "amxmodx.org", iPort = 80, iError; public plugin_init() {     register_plugin("Sockets Example", "0.2", "hackzinger + Dygear");     g_iSocket = socket_listen(szAddress, iPort, SOCKET_TCP, iError);     socket_unblock(g_iSocket);     set_task(1.0, "fwSocketAccept", 0, "", 0, "b"); } public plugin_end() socket_close(g_iSocket); public fwSocketAccept() {     new iSocket;     if( (iSocket = socket_accept(g_iSocket)) < 0 )         server_print("No pending connection");     else {         new szHttpReq[128], iReqSz = (sizeof(szHttpReq) - 1);         format(szHttpReq, iReqSz, "GET / HTTP/1.1^nHost: %s^n^n", szAddress);         socket_send(iSocket, szHttpReq, iReqSz);         socket_close(iSocket);     } }

Ramono 09-19-2010 12:23

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by Exolent[jNr] (Post 808939)
Currently, the only way to have this method is supply the IP in the data that I am sending.
I'd like a better way such as socket_info(socket, ip[], len, &port).

I too would like a way to retrieve a sockets IP-adress. Sending it along with the data is impossible as the client connected to my plugin in a http browser.
The function decribed by Exolent[jNr] would be perfect.

issen1 10-18-2010 06:56

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by joaquimandrade (Post 987895)
A folk remembered me that I modified this module for use in a plugin of mine. The difference is that since socket_open does one operation in blocking mode it still can hang the server. So, this version brings socket_open_non_blocking so all the operations can be done in non blocking mode. Source, win and linux version in the zip file here http://forums.alliedmods.net/showthread.php?t=99516

(Confirmed by hackziner)

Can someone edit this in the first post, please? I was nearly about to edit hz original package myself. Thank you!


All times are GMT -4. The time now is 14:13.

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