Raised This Month: $32 Target: $400
 8% 

Sockets


Post New Thread Reply   
 
Thread Tools Display Modes
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
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 08-17-2018 , 00:49   Re: Sockets
Reply With Quote #2

Anything?
__________________
ambn is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-17-2018 , 02:46   Re: Sockets
Reply With Quote #3

A delimiter appears to be missing.

Try adding \n at the end of what you send.
__________________
Neuro Toxin is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 08-17-2018 , 02:47   Re: Sockets
Reply With Quote #4

okay, i'll check it now and let you know
__________________
ambn is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 08-17-2018 , 02:52   Re: Sockets
Reply With Quote #5

okay as you said i made these changes:
Quote:
SocketSend(socket, "PONH"); --> SocketSend(socket, "PONH\n");
still i get connected but the message does not show on the server's console , any other idea or working examples?
__________________
ambn is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-17-2018 , 13:00   Re: Sockets
Reply With Quote #6

A newline or not isn't going to matter at the socket level. I compiled your script without changes and it works for me.

Server console:
Code:
sm plugins reload sock
[SM] Plugin sock.smx reloaded successfully.
[SOCKET] Connected.
sm_ech
Shell:
Code:
$ nc -l -p 6500
PONHERRRRR
Your other end is doing something you don't expect. Maybe it's only listening on an external interface.
Fyren is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 08-17-2018 , 13:49   Re: Sockets
Reply With Quote #7

Well that make no sense but thanks for letting me know the problem could be something esle ill test more and reply
__________________
ambn is offline
Reply


Thread Tools
Display Modes

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 04:54.


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