Thread: Sockets
View Single Post
Author Message
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 08-16-2018 , 01:33   Sockets
Reply With Quote #1

hi, i'm trying to send a simple string through socket to my java socket server (i'm pretty sure the server is okay cuz i've tested it with several other tools to see of it really echos what ever you send to it though socket), but unfortunately after i get connected to the socket nothing else really happens, i can't send a socket message, the server says i'm connected but the plugin's forward for connection does not print me the string i wrote into the forward. any help? here is my code and all i want for now is a simple string to be sent only(not received):
PHP Code:
#include <sourcemod>
#include <socket>

Handle:socket INVALID_HANDLE;

public 
OnPluginStart() {
    
// create a new tcp socket
    
socket SocketCreate(SOCKET_TCPOnSocketError);
    
// connect the socket
    
SocketConnect(socketOnSocketConnectedOnSocketReceiveOnSocketDisconnected"localhost"6500)
    
    
RegServerCmd("sm_ech"Ech);
}

public 
Action Ech(int args)
{
    
SocketSend(socket"ERRRRR");
}

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

    
PrintToServer("[SOCKET] Connected.");
    
SocketSend(socket"PONH");
}

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

    
PrintToServer("[SOCKET] New Data: %s"receiveData);
}

public 
OnSocketDisconnected(Handle:socketany:hFile) {
    
// Connection: close advises the webserver to close the connection when the transfer is finished
    // we're done here
    
    
PrintToServer("[SOCKET] Disconnected.");
    
CloseHandle(socket);
    
socket INVALID_HANDLE;
}

public 
OnSocketError(Handle:socket, const errorType, const errorNumany:hFile) {
    
// a socket error occured
    
    
PrintToServer("[SOCKET] socket error %d (errno %d)");
    
CloseHandle(socket);
    
socket INVALID_HANDLE;

Any help?
__________________
ambn is offline