Code Monkey home page Code Monkey logo

d2httpsocket's Introduction

D2HTTPSocket

Extended flash socket implementing a basic version of the HTTP protocol to be used in dota 2 UI.

The file that matters is D2HTTPSocket.as, an example of how to use this class can be found in sockethttp.as.

How to use:

Importing

First of all import the class:

import dota2Net.D2HTTPSocket;

Initialisation

Then in initialise the socket at some point, onLoaded is recommended. Initialisation looks like this:

var socket:D2HTTPSocket = new D2HTTPSocket(hostName:String, hostIP:String [, ignoreHeaders:Boolean = true] );

The constructor takes a hostName and hostIP parameter which are for example 'someDomain.eu' and '8.8.8.8'. Note: these are strings. Optionaly an ignoreHeaders parameter can be supplied, which determines if HTTP headers are stripped from response messages (also see Callback format). This is true by default.

The socket is persistent as long as your UI exists, so should probably be saved in an instance variable.

GET Request

GET requests are requests for data at some URL that do not send any data with the request except for parameters in the URL. These requests can be used to retrieve data from a location. These requests are doen asynchronously, so a callback should be provided to handle the data once it is returned.

GET request code:

socket.getDataAsync( path:String, callback:Function );

POST Request

POST requests are commonly used for sending data to a server. This method does not include the data in the URL unlike GET requests. This request is also done asynchronously, but since POST requests are done for transmitting it is optional. It is however recommended to also handle the returns for these requests, so you can check if the request was successful.

POST request code:

socket.postDataAsync( path:String, data:String [, callback:Function] );

Callback format

After a request returns a callback is called. This callback should be in the following format:

function callback( statusCode:int, data:String ) {
  /* do something here, for example:
  if (statusCode == 200) {
    //success! Do something
  } else {
    //error happened...
  } */
}

The statuscode can be used to do a fast check if the request was successful or not (200 is success, read up on HTTP status codes). The data parameter contains the data returned by the request. By default the headers are stripped from this, unless configured otherwise (see Initialisation).

d2httpsocket's People

Contributors

bmddota avatar perryvw avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.