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

[EXTENSION] Socket (3.0.1)


Post New Thread Reply   
 
Thread Tools Display Modes
koshmel
Member
Join Date: Nov 2008
Old 11-12-2008 , 16:58   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #61

How read Binary data(JPG. DEM file)?
i use
Code:
decl String:Buff[10000];
while (!IsEndOfFile(OFile))
        {
            ReadFileString(OFile,Buff,10000)
            SocketSend(socket,Buff);
        }
but it's wrong work with binary data.
koshmel is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 11-16-2008 , 15:41   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #62

Open the file with the mode "rb+".
bl4nk is offline
Kigen
BANNED
Join Date: Feb 2008
Old 11-17-2008 , 06:21   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #63

Actually it appears some corruption occurs when sending/receiving binary data with this plugin.
Kigen is offline
koshmel
Member
Join Date: Nov 2008
Old 11-17-2008 , 15:59   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #64

Quote:
Originally Posted by bl4nk View Post
Open the file with the mode "rb+".
What's it's mean?)
How i read (:

Code:
decl Buff[1005];
new BuffL=0;
    while (!IsEndOfFile(OFile))
        {
            BuffL=ReadFile(OFile, Buff, 250,4);
            if (BuffL<250)
                {BuffL=FileSize(UploadFileName)%1000;}
                else{BuffL=1000;}
            SocketSend(socket,Buff,BuffL);
        }
It's work's)
maybe it's work only on 32-bit's system

Last edited by koshmel; 11-17-2008 at 16:06.
koshmel is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 11-17-2008 , 16:10   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #65

OpenFile("file.txt", "rb+");
bl4nk is offline
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 11-19-2008 , 17:27   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #66

As mentioned in the documentation (-> socket.inc), you have to pass the data length in SocketSend for binary data as you've done in your 2nd code snippet otherwise the extension will send only up to the first \0 character.

srcds is always running in 32bit mode, even if you are using a 64bit OS.
sfPlayer is offline
StevoTVR
Senior Member
Join Date: Oct 2008
Old 11-23-2008 , 20:26   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #67

There seems to be a memory leak with this extension. I'm working on a plugin that requires downloading a different page on a website for each connecting client. It works, but the server started crashing frequently and I noticed the committed memory was up to about 5Gb before the crashes.

Version: 2.4.0
OS: Fedora Core 9
Games: Insurgency, DoD:S, TF2

I used this plugin to test:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <socket>

#define PLUGIN_VERSION "1.0.0"

public Plugin:myinfo 
{
    
name "Socket Test",
    
author "Unknown",
    
description "Test",
    
version "1.0",
    
url ""
}

public 
OnPluginStart()
{
    
RegAdminCmd("sm_socket_test"CommandTestADMFLAG_CONVARS"test");
}

public 
Action:CommandTest(clientargs)
{
    
// create a new tcp socket
    
new Handle:socket SocketCreate(SOCKET_TCPOnSocketError);
    
// open a file handle for writing the result
    
new Handle:hFile OpenFile("dl.htm""wb");
    
// pass the file handle to the callbacks
    
SocketSetArg(sockethFile);
    
// connect the socket
    
SocketConnect(socketOnSocketConnectedOnSocketReceiveOnSocketDisconnected"www.sourcemod.net"80);
    return 
Plugin_Handled;
}

public 
OnSocketConnected(Handle:socketany:hFile) {
    
// socket is connected, send the http request

    
decl String:requestStr[100];
    
Format(requestStrsizeof(requestStr), "GET /%s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n""index.php""www.sourcemod.net");
    
SocketSend(socketrequestStr);
}

public 
OnSocketReceive(Handle:socketString:receiveData[], const dataSizeany:hFile) {
    
// receive another chunk and write it to <modfolder>/dl.htm
    // we could strip the http response header here, but for example's sake we'll leave it in

    
WriteFileString(hFilereceiveDatafalse);
}

public 
OnSocketDisconnected(Handle:socketany:hFile) {
    
// Connection: close advises the webserver to close the connection when the transfer is finished
    // we're done here

    
CloseHandle(hFile);
    
CloseHandle(socket);
}

public 
OnSocketError(Handle:socket, const errorType, const errorNumany:hFile) {
    
// a socket error occured

    
LogError("socket error %d (errno %d)"errorTypeerrorNum);
    
CloseHandle(hFile);
    
CloseHandle(socket);

Every time I ran the command, the committed memory increased by about 20Mb. So there's either a memory leak in the extension or I'm doing something wrong.

Any help would be appreciated.
StevoTVR is offline
Scipio
Junior Member
Join Date: Sep 2008
Old 11-24-2008 , 04:16   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #68

I've been running this extension for sometime now with no problems, now that I have moved to a new game provider it's causing players to get blocked from my server with the message: client dropped from server. I read somewhere that it's caused by firewall settings on the server, could I get all the details about this so I can get my provider to fix this, thanks.
Scipio is offline
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 11-24-2008 , 10:52   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #69

I can reproduce the memory leak, but I can't find its cause. The socket extension's allocations are mostly below 100Byte, the largest is the 4kB receive buffer. I've also tried Valgrind without success.

The memory stays allocated even after I unload the socket extension, maybe there is a problem within SM.

m@mkpc:~/srcds$ cat /proc/22220/status |grep VmSize
VmSize: 161216 kB
>sm_socket_test
m@mkpc:~/srcds$ cat /proc/22220/status |grep VmSize
VmSize: 177724 kB
>sm_socket_test
m@mkpc:~/srcds$ cat /proc/22220/status |grep VmSize
VmSize: 194116 kB
>sm exts unload 4
>sm exts unload 4 910
m@mkpc:~/srcds$ cat /proc/22220/status |grep VmSize
VmSize: 194056 kB
sfPlayer is offline
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 11-24-2008 , 17:30   Re: [EXTENSION] Socket (2.4.0beta+2.1)
Reply With Quote #70

I've got two solutions, one requires SourceMod to be patched, the other one needs some ugly workaround.

Last edited by sfPlayer; 11-24-2008 at 18:32.
sfPlayer 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 19:45.


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