sockets plugin: request help
#1

https://sampforum.blast.hk/showthread.php?tid=171598 - Read before continuing

I am using it on my local host right now. However, it seems it cannot send information properly if it isn't the host (start_listening)

This is my code:
pawn Код:
...   //This is the responding client
#include <sockets>
public OnSocketConnect(address[],port)
{
    if ( strcmp(address, "127.0.0.1") != 0 ) // not a loacal connection!
    {
        socket_close();
    }
    return 1;
}
forward message();
public OnSocketReceive(data[], address[], port)
{
    // do something
    SetTimer("message",1000,false);
    return 1;
}

public OnGameModeInit()
{
    //socket_startlistening(7000);
    socket_connect("127.0.0.1",7000);
    socket_send("yo");
    return 1;
}


public message()
{
    socket_send("yo");
}

=============================

... //This is the server
#include <sockets>

public OnSocketConnect(address[],port)
{
    if ( strcmp(address, "127.0.0.1") != 0 ) // not a loacal connection!
    {
        socket_close();
    }
    return 1;
}
forward message();
public OnSocketReceive(data[], address[], port)
{
    // do something
    SetTimer("message",1000,false);
    return 1;
}

public OnGameModeInit()
{
    socket_startlistening(7000);
    //socket_connect("127.0.0.1",7000);
    //socket_send("yo");
    return 1;
}


public message()
{
    socket_send("yo");
}
I have considered the order in which the 2 programs should start. In the right order, the server answers after 1 second with "yo", while the other server that is connected doesn't seem to receive anything as it doesn't execute the same. This indeed should create an endless loop of yo's.

Why isn't this happening?

I have no experience in reading plugin sources, otherwise I'd be doing that. I'd appreciate it if someone could.

I am on a windows 32-bit 7 ultimate edition. No firewalls blocking. Both server are hosted locally.
Nearly impossible to find a packet sniffer that reads localhost packets as most are purely for network analyzing.
I can't figure out whether it even reaches the server or not.

Thank you!
Reply
#2

bump
Reply
#3

Try using socket_send in the callback which is called once you have connected, so:

pawn Код:
public OnSocketConnect(address[], port) {
    if(strcmp(address, "127.0.0.1") != 0) // not a local connection!
        return socket_close();

    socket_send("yo");
    return 1;
}
I don't think you can just send "yo" though.
Reply
#4

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
Try using socket_send in the callback which is called once you have connected, so:

pawn Код:
public OnSocketConnect(address[], port) {
    if(strcmp(address, "127.0.0.1") != 0) // not a local connection!
        return socket_close();

    socket_send("yo");
    return 1;
}
I don't think you can just send "yo" though.
After some googling, I figured out I may need to stop the message with \r\n.
I've changed this but doesn't make a difference.

As what you said, if you can't just send "yo\r\n" after making a connection (which is why I made the timer, to make sure it is connected by giving it some handling time) then the plugin kinda is a waste isn't it?
Reply
#5

No I mean that you might need to send some extra headers to indicate that it's merely a message you're trying to send, this plugin probably only accepts particular headers.
Reply
#6

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
No I mean that you might need to send some extra headers to indicate that it's merely a message you're trying to send, this plugin probably only accepts particular headers.
I figured this might be the case, which is why I have a problem and am requesting for help.

Since I am not even close in understanding the programming environment of c++ (and biggest bits of), which is the source's code language, I can't figure this out myself.

However, even considering this, you would imagine the plugin writer made it so it would work with 2 servers together. (one posing as listening server, the other one as connecting client.)
Which they don't. (not unless it is at gamemode init)

After some thinking and testing, I am considering the fact that HTTP protocol may have something to do with it.
Maybe something about sockets, which may be likely for me to believe.

Which is why I once again, hate the shortage in proper documentation of pawn namely, the http function in pawn.
Unfortunately to us, there is no link to resources to figure it out yourself.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)