Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-09-2012, 09:06 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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);?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 04-09-2012, 01:04 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I've already explained this to you .
__________________
Reply With Quote
  #3  
Old 04-09-2012, 02:24 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 04-09-2012 at 04:31 PM..
Reply With Quote
  #4  
Old 04-10-2012, 02:23 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Post your GScript code.
__________________
Reply With Quote
  #5  
Old 04-10-2012, 03:03 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 04-10-2012 at 03:19 AM..
Reply With Quote
  #6  
Old 04-10-2012, 09:39 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #7  
Old 04-14-2012, 05:58 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #8  
Old 04-14-2012, 06:08 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #9  
Old 04-14-2012, 08:51 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #10  
Old 04-15-2012, 04:22 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #11  
Old 04-15-2012, 04:30 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Reply With Quote
  #12  
Old 04-15-2012, 05:59 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 04-15-2012 at 06:11 AM..
Reply With Quote
  #13  
Old 04-15-2012, 06:28 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Reply With Quote
  #14  
Old 04-15-2012, 08:10 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #15  
Old 04-15-2012, 09:11 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
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 +2. The time now is 03:32 PM.


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