0% found this document useful (0 votes)
45 views

39ster: If (!sockid) (Show - Message ("Unable To Connect To Google") )

This tutorial explains how to communicate with text-based protocols like HTTP using 39DLL. It describes connecting to a server, sending a GET request, and receiving the response. The key steps are: 1. Connect to the server and set the socket format to include carriage returns and newlines. 2. Build and send a GET request with headers to execute a PHP file. 3. Receive the response header and payload, displaying the payload.

Uploaded by

nathan818magic
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

39ster: If (!sockid) (Show - Message ("Unable To Connect To Google") )

This tutorial explains how to communicate with text-based protocols like HTTP using 39DLL. It describes connecting to a server, sending a GET request, and receiving the response. The key steps are: 1. Connect to the server and set the socket format to include carriage returns and newlines. 2. Build and send a GET request with headers to execute a PHP file. 3. Receive the response header and payload, displaying the payload.

Uploaded by

nathan818magic
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Text based protocols with 39DLL 39ster

This tutorial was written to help programmers communicate with text based protocols such as HTTP, IRC, etc. The tutorial is written for 39DLL which gives you access to windows sockets, which is required to communicate with these protocols. Stuff to know before you read the tutorial: [crlf] = New Line ----- chr(13) + chr(10)

1. Starting off The first thing you need to do is connect to the server you want to communicate with. To do this, use the script tcpconnect() to connect to the server. sockId = tcpconnect("www.google.com.au", 80, 0); if(!sockId) { show_message("Unable to connect to google"); } The above code will attempt to connect to googles server on port 80. If it fails to connect for any reason it will show an error message. Once we have succesfully connected to the server, we need to change our format mode for the socket. Because 39DLL was designed for games, by default it sends messages in a format that is incompatible with text based protocols. To change the format to make our packets compatible with text based formats, we use the script setformat(). setformat(sockId, 1, chr(13) + chr(10)); The above code will change the format mode for our socket to format mode 1. In format mode 1 all our messages are sent with a token string added to the end of it. This token string is also used for receiving messages, to let receivemessage() know that we only want to receive until we reach that token string. In this case we only want to receive as much bytes until we get to the characters chr(13) + chr(10). chr(13) + chr(10) is called a new line. So in other words, we only want to receive one line at a time. So if our modem receives this packet: GET /blah HTTP/1.1[crlf] Host: something.com[crlf] [crlf] we would only receive the first line (the line starting with GET) 2. Sending a message Now that we're connected to the server, we need to send a message in order for something to happen. So if we want to execute a PHP file on the remote server we need to build a GET request and send it through the socket. Lets say the file is called "myfile.php" and you normally execute it by going to this URL: http://google.com.au/myfile.php?msg=HELLO

To do this exact same thing in the dll we do this: newLine = chr(13) + chr(10); clearbuffer(); writechars("GET /myfile.php?msg=HELLO HTTP/1.0" + newLine); writechars("Host: www.google.com.au" + newLine); sendmessage(sockId); NOTE: normally in a HTTP get request you're required to add one extra blank newLine at the end of the packet, but the format mode automatically adds the newline characters for us. The above code will write a get request to the buffer and send it through our socket. Our packet will look like this: GET /myfile.php?msg=HELLO HTTP/1.0[crlf] Host: www.google.com.au[crlf] [crlf] Thats all you have to do to execute the php file. 3. Receiving data from the server Once you have sent your message to the server, you may be expecting to receive something back. The php file may contain data that you want to use in your game. processHeader = true; while(processHeader) { receivemessage(sockId); firstWord = readsep(newLine); switch(firstWord) { case "": //blank line processHeader = false; break; //read important stuff from header... } } The above code will receive every line of the reply header. Once we have received all the reply header, the data sent from the php file is sent (payload). To receive this we need to change our format mode to 2, because we do not want our receivemessage() to read in any specific format. setformat(sockId, 2); retVal = ""; while(1) { size = receivemessage(sockId, 6000); if(size > 0) retVal += readchars(size); else break; } show_mesage(retVal);

closesocket(sockId); The above code will receive all of the payload and put it in the variable "retVal" than show it in a show_message() This is what our end code will look like: sockId = tcpconnect("www.google.com.au", 80, 0); if(!sockId) { show_message("Unable to connect to google"); exit; } setformat(sockId, 1, chr(13) + chr(10)); newLine = chr(13) + chr(10); clearbuffer(); writechars("GET /myfile.php?msg=HELLO HTTP/1.0" + newLine); writechars("Host: www.google.com.au" + newLine); sendmessage(sockId); processHeader = true; while(processHeader) { receivemessage(sockId); firstWord = readsep( ); switch(firstWord) { case "": //blank line processHeader = false; break; //read important stuff from header... } } setformat(sockId, 2); retVal = ""; while(1) { size = receivemessage(sockId, 6000); if(size > 0) retVal += readchars(size); else break; } show_message(retVal); closesocket(sockId);

You might also like