Raised This Month: $51 Target: $400
 12% 

[INC] Sockets Forwards


Post New Thread Reply   
 
Thread Tools Display Modes
andre neves
Junior Member
Join Date: Mar 2011
Old 11-20-2011 , 12:51   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #11

please read my question: http://forums.alliedmods.net/showthread.php?t=171856
andre neves is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 11-25-2011 , 10:19   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #12

Quote:
Originally Posted by Bugsy View Post
The main difference is this inc/module combo uses a thinking entity to monitor changes to trigger forwards and the windows-only module gets notified by the OS of changes so no looping/set_task/thinking-ent. The overall functionality is the same.
Why not to check on ServerFrame for socket data available using select with non-blocking sockets? It will be smoothest for the socket operation.

I've made that modification in sockets module just for testing purposes and it works like a charm.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 12-31-2011 , 18:05   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #13

It is posible to restrict the socket to accept connections from one IP only ? Thank you.
DjOptimuS is offline
Javivi
AlliedModders Donor
Join Date: Dec 2008
Old 01-05-2012 , 10:52   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #14

Hello bugsy, good job.

Sometimes a non-blocking socket can return EINPROGRESS at connect, so that check will fail and the socket won't be created ( but it should be created, and then checked with socket_is_writable to see when the socket is ready for sending data )

PHP Code:
    if ( ( ( connect(sock, (struct sockaddr*)&server sizeofserver ) ) ) == SOCKET_ERROR ) && ( GetSocketError() != WOULDBLOCK ) ) 
    {
            *
err GetSocketError(); 
            return -
1;
    } 
Joaquim's version works fine
PHP Code:
    // Not, let's try to open a connection to the server
    
contr connect(sock, (struct sockaddr*)&serversizeofserver));
    
    
/*
    if (contr < 0) {
            // If an error occured cancel
            params[4] = 3;  //error while connecting
            return -1;
    }
    */ 
__________________
Javivi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-08-2012 , 17:10   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #15

I partially rewrote this module eliminating the need for the sockets_forwards.inc file, as recommended by joropito. The module will now monitor socket events\changes without any type of looping\checking within the .inc or plugin. It is working under WinXP, can someone compile\test under linux?
__________________

Last edited by Bugsy; 04-08-2012 at 17:11.
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-08-2012 , 17:20   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #16

No idea if it loads/works.
Attached Files
File Type: so sockets2_amxx_i386.so (12.2 KB, 175 views)
__________________
Arkshine is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-08-2012 , 17:26   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #17

Quote:
Originally Posted by Arkshine View Post
No idea if it loads/works.
I didn't post the new one yet, just seeing if I had any takers on a compile test. Ill post in a few
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-08-2012 , 18:20   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #18

Here it is, thanks in advance.
Attached Files
File Type: zip Sockets2Module.zip (46.1 KB, 259 views)
__________________
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-08-2012 , 18:33   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #19

Needs to be tested.
Attached Files
File Type: so sockets2_amxx_i386.so (23.3 KB, 218 views)
__________________
Arkshine is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-08-2012 , 19:49   Re: [INC/MODULE] Sockets Forwards
Reply With Quote #20

Quote:
Originally Posted by Arkshine View Post
Needs to be tested.
Here's a little plugin I put together to quickly test the module, example #2 above also works if you have a separate sockets tester app to work with (AMXX Studio sockets terminal works good for Windows)

To test Server\Client functionality, do commands in this order:
1. Listen (use only once, this creates a listening socket)
2. Connect (can be repeated, each time a new client is created)
3. SendData (can be repeated, will send from most recent connected client)

To quickly test an HTTP request use Test command.

PHP Code:
#include <amxmodx>
#include <sockets2>

const TEST_PORT 234;

new 
g_Socket;

public 
plugin_init() 
{
    
register_concmd"Test" "QuickTest" );
    
register_concmd"Connect" "TestConnect" );
    
register_concmd"Listen" "TestListen" );
    
register_concmd"SendData" "TestSend" );
}

public 
QuickTest()
{
    new 
iError;
    new 
iSocket socket_open"www.google.com" 80 SOCKET_TCP iError );
    
    
server_print"Connecting on=%d Error=%d" iSocket iError );
}

public 
TestConnect()
{
    new 
szIP16 ] , iError;
    
get_user_ipszIP charsmaxszIP ) , );
    
    
g_Socket socket_openszIP TEST_PORT SOCKET_TCP iError );
    
    
server_print"Connecting on=%d Error=%d" g_Socket iError );
}

public 
TestListen()
{
    new 
szIP16 ] , iError iSocket;
    
get_user_ipszIP charsmaxszIP ) , );

    
iSocket socket_listenszIP TEST_PORT SOCKET_TCP iError ); 
    
    
server_print"Listening on=%d Error=%d" iSocket iError );
}

public 
TestSend()
{
    
server_print"Sending data on=%d" g_Socket );
    
socket_sendg_Socket "Hello there" 12 ); 
}

public 
Socket_ConnectediSocket )
{
    
server_print"Connected on=%d" iSocket );
    
socket_sendiSocket "GET /index.html HTTP/1.1^r^nHost: www.google.com^r^n^r^n" 128 );
}

public 
Socket_ConnectionRequestiSocket )
{
    new 
iError;

    if ( ( 
g_Socket socket_acceptiSocket iError ) ) )
        
server_print"Connect Request on=%d, Accepted request, new socket=%d" iSocket g_Socket );
}

public 
Socket_IncomingDataiSocket iBytes )
{
    new 
szData1024 ] , iGet socket_recviSocket szData sizeofszData ) );
    
    
server_print"Data Arrived on %d | Total Bytes=%d | Bytes-read=%d | Data=%s" iSocket iBytes iGet szData );
}

public 
Socket_DisconnectediSocket )
{
    
server_print"Disconnected=%d" ,iSocket );

__________________

Last edited by Bugsy; 04-08-2012 at 20:32.
Bugsy 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 18:31.


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