Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   TSockets (https://forums.graalonline.com/forums/showthread.php?t=134266208)

Gunderak 04-09-2012 09:06 AM

TSockets
 
Hello, I am having a little trouble connecting a TSocket.
Each time I try I get this error.

Script connection to http://wr3ckless.net:0 is not allowed, blocking.

Maybe I am doing something wrong?
My ultimate goal is to make the GServer listen on a host/port, in which it allows me to send data from a webserver to to GServer.
Here is what I have experimented with.
PHP Code:

function onCreated(){
  
temp.socket = new TSocket();
  
socket.bind(0false);
  
socket.connect("http://wr3ckless.net"0);
  
thiso.catchevent(socket"onConnect""onConnected");
}
function 
onConnected(){
  echo(
"TSocket Connected: "@params);


Additionally is there any type of socket.listen(host, port);?

cbk1994 04-09-2012 01:04 PM

I've already explained this to you x_x.

Gunderak 04-09-2012 02:24 PM

Ok well I stuffed up a bit there.
But now that that's working; sending data via PHP on the other hand isn't.

Here is my understanding of sockets.

For the server:
So first it creates a socket.
Next it binds the socket to a port.
Then it listens on the port.
Then if data is sent it accepts it.

For the client sending data:
First it creates a socket.
It then connects to the socket using the ip and port.
It then can send data through the socket.

Edit: I am getting this error in PHP
Host lookup failed [-10003]: Unknown server error
It also gives this error.
unable to connect to 50.23.136.181:58860 (Connection refused)

Here is my PHP code..
PHP Code:

  $host '50.23.136.181';
  
$port '41106';

  
$sock socket_create(AF_INETSOCK_STREAMSOL_TCP);
  
socket_connect ($sock$ip$port);
  
$dat 'Test';
  
$len strlen($msg);
  
socket_send($sock$dat$lenMSG_OOB);
  
socket_close($sock); 

I tried UDP and ICMP for creating the sockets, but they gave even more errors; I assume it's TCP?

I did however manage to get the GServer to echo data, but I had to connect to the ip and port using a socket testing program.
My main goal is to have an input text box and a send button.

cbk1994 04-10-2012 02:23 AM

Post your GScript code.

Gunderak 04-10-2012 03:03 AM

The GScript code is just echo's Bound to: ip : port waiting
And it works if I connect to it via a socket testing program, but via PHP it won't connect; it either gives connection refused or various other errors.
When I get on my PC however I will post it.
Additionally if it helps before I can get to my computer, to open a socket it uses your http_listensocket and http_socketconnect if I recall the names correctly.

Gunderak 04-10-2012 09:39 AM

Here is the GS2..
PHP Code:

function onCreated() {
  
temp.req requestURL("http://automation.whatismyip.com/n09230945.asp");
  
  
waitfor(req"onReceiveData"30);
  
this.ip req.data[0];
  
  if (
isObject("HTTPListenSocket")) {
    
HTTPListenSocket.destroy();
  }
  
  
this.listenSocket = new TSocket("HTTPListenSocket");
  
this.listenSocket.optionDB this;
  
this.listenSocket.join("http_listensocket");


I managed to send data to it via HTML5 websockets but it only echo's the handshake and not the data being sent from the onReceiveData part.

Gunderak 04-14-2012 05:58 PM

I'm having an issue with the socket still.
I am sending data to it via a HTML5 websocket.
It is echoing what I believe to be the handshake and not the actual data being send.
This is coming in when onReceiveData is triggered.

GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 50.23.136.181:57248
Origin: http://wr3ckless.net
Sec-WebSocket-Key: TTMGSf/g8hepQm7K1ZK6RA==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame

cbk1994 04-14-2012 06:08 PM

Did you look at the WebSocket protocol (RFC)? A quick read of the opening handshake indicates that you're going to have to reply with a 101 status code and a Sec-WebSocket-Accept header; see the RFC for how to get the value for that header.

Quote:

Originally Posted by Example Response Headers, RFC 6455
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

Once you've completed the handshake you can worry about sending data.

I don't know why you're using WebSockets for this anyway. You shouldn't need to talk from a browser -> the Graal server directly, so do it via some serverside language with regular old sockets.

Admins 04-14-2012 08:51 PM

There is web-socket support in Graal but only for the Graal connection itself not for TSocket. It's pretty complex so some custom implementation is not recommended.
If you want to communicate with the Graal server it can be easier to use server-side communication (a php script or so) or just use http requests.

Gunderak 04-15-2012 04:22 AM

I tried to use PHP but it kept giving connection refused errors as I don't know the configuration, eg weather it's UDP, TCP or what.

cbk1994 04-15-2012 04:30 AM

Quote:

Originally Posted by Gunderak (Post 1692146)
I tried to use PHP but it kept giving connection refused errors as I don't know the configuration, eg weather it's UDP, TCP or what.

It's going to be TCP. You don't normally use UDP for this kind of stuff.

Gunderak 04-15-2012 05:59 AM

I tried it with TCP and it just gave a connection refused error.
Could you happen to give me an example of one that successfully connects and sends some data?

cbk1994 04-15-2012 06:28 AM

Quote:

Originally Posted by Gunderak (Post 1692153)
I tried it with TCP and it just gave a connection refused error.
Could you happen to give me an example of one that successfully connects and sends some data?

Talk to it with telnet and see if it responds. That's typically the best way to troubleshoot this kind of stuff.

Gunderak 04-15-2012 08:10 AM

That's a rather good idea. I shall give it a shot when I get home.
Atleast this way I should be able to see the responses.

Gunderak 04-15-2012 09:11 AM

OK so I managed to connect to it via telnet.
Whatever I wrote was echo'd when I made it echo the data on onReceiveData.
So my next step would to get this to work with PHP I suppose.


All times are GMT +2. The time now is 12:31 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.