Raised This Month: $ Target: $400
 0% 

Using SOCKET_TCP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-11-2008 , 21:54   Using SOCKET_TCP
Reply With Quote #1

I currently am using SOCKET_UDP to transfer data between my servers.
I've read and searched around the forums for quite awhile, but I can't see to figure out how TCP works.
Can someone give me an example at how to use SOCKET_TCP to transfer data between servers?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-11-2008 , 22:04   Re: Using SOCKET_TCP
Reply With Quote #2

Quote:
Originally Posted by Exolent[jNr] View Post
I currently am using SOCKET_UDP to transfer data between my servers.
I've read and searched around the forums for quite awhile, but I can't see to figure out how TCP works.
Can someone give me an example at how to use SOCKET_TCP to transfer data between servers?
A good brief comparison: http://www.devmaster.net/wiki/UDP_vs_TCP

Edit: I'm not 100% sure if it is possible to establish a server-to-server TCP connection since there is no listen function in sockets. For TCP communication you need one end to be listening for a connection and the other end to do the connection request. The connection request is handled with socket_open but there is no way to make one end listen for the connection. Sockets may be limited to only establishing a TCP connection with an already existing server. I have written an SMTP email function in pawn but I don't think it is a great example for TCP as it is so basic.
__________________

Last edited by Bugsy; 11-12-2008 at 00:49.
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-12-2008 , 05:29   Re: Using SOCKET_TCP
Reply With Quote #3

Maybe reading hackziner's plugin will help you.

Quote:
since there is no listen function in sockets.
If I understand well, hackziner has done something like : http://forums.alliedmods.net/showthread.php?t=60026
__________________
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-12-2008 , 07:12   Re: Using SOCKET_TCP
Reply With Quote #4

Thanks, Bugsy. My problem was that I didn't have a socket "listening" to accept data on the servers, so I couldn't connect.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 11-12-2008 , 07:47   Re: Using SOCKET_TCP
Reply With Quote #5

Yea, sockets_hz , edit by hackziner are awesome...works fine and have listening , also read some doc's about that module, beacause you will ned to unblock socket and so...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-12-2008 , 11:22   Re: Using SOCKET_TCP
Reply With Quote #6

Alka, could you give me an example of how this would work?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 11-12-2008 , 12:23   Re: Using SOCKET_TCP
Reply With Quote #7

What are you making? I have an idea for a plugin but it's pretty dam intensive, I don't know if a server would survive with it ... heh
Styles is offline
Send a message via AIM to Styles
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-12-2008 , 12:40   Re: Using SOCKET_TCP
Reply With Quote #8

I've made a sample to test but I have to go now.

How does this look?

Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #include <sockets_hz> #define IP  "127.0.0.1" #defien PORT    27015 new g_socket; new g_think_ent; public plugin_init() {     register_plugin("TCP Socket Test (Reader)", "0.1", "Exolent");         new error;     g_socket = socket_listen(IP, PORT, SOCKET_TCP, error);         if( error )     {         switch( error )         {             case 1: log_amx("Error creating a TCP socket to %s:%i", IP, PORT);             case 2: log_amx("Error resolving the hostname for %s:%i", IP, PORT);             case 3: log_amx("Error connecting a TCP socket to %s:%i", IP, PORT);         }                 return;     }         socket_unblock(g_socket);         log_amx("Created TCP Socket listening for any IP on port %i", PORT);         new info_target = engfunc(EngFunc_AllocString, "info_target");     while( !(g_think_ent = engfunc(EngFunc_CreateNamedEntity, info_target)) ) { }         set_pev(g_think_ent, pev_classname, "TCP_Socket_Reader");     set_pev(g_think_ent, pev_nextthink, get_gametime() + 0.01);         register_forward(FM_Think, "FwdThink"); } public plugin_end() {     if( g_socket > 0 )     {         socket_close(g_socket);     } } public FwdThink(ent) {     if( ent != g_think_ent ) return;         static socket;         if( (socket = socket_accept(g_socket)) > 0 )     {         new data[1024];         socket_recv(socket, data, sizeof(data) - 1);                 log_amx("Received data: %s", data);     }         set_pev(g_think_ent, pev_nextthink, get_gametime() + 0.01); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 11-12-2008 , 13:21   Re: Using SOCKET_TCP
Reply With Quote #9

Looks fine, but don't use 27015 port, use another one that is not used by any application.

@styles - What idea? tell me , tell me...*happy*
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 11-12-2008 , 13:55   Re: Using SOCKET_TCP
Reply With Quote #10

Alka I'll pm you the idea :p
Styles is offline
Send a message via AIM to Styles
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 06:15.


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