Last active
December 17, 2015 11:09
-
-
Save bricecarpentier/5599788 to your computer and use it in GitHub Desktop.
This is a simple websocket client using https://github.com/Worlize/AS3WebSocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Sprite; | |
import com.worlize.websocket.WebSocket; | |
import com.worlize.websocket.WebSocketEvent; | |
import com.worlize.websocket.WebSocketErrorEvent; | |
public class Main extends Sprite | |
{ | |
private var _socket:WebSocket; | |
public function Main() | |
{ | |
trace('[client] started'); | |
_socket = new WebSocket('ws://localhost:5001', '*'); | |
_socket.addEventListener(WebSocketEvent.CLOSED, onClosed); | |
_socket.addEventListener(WebSocketEvent.OPEN, onOpen); | |
_socket.addEventListener(WebSocketEvent.MESSAGE, onMessage); | |
_socket.addEventListener(WebSocketErrorEvent.CONNECTION_FAIL, onFail); | |
_socket.connect(); | |
} | |
protected function onClosed(event:WebSocketEvent):void | |
{ | |
trace('[client] connection closed'); | |
} | |
protected function onOpen(event:WebSocketEvent):void | |
{ | |
trace('[client] connection open'); | |
_socket.sendUTF('3|Hello'); | |
} | |
protected function onMessage(event:WebSocketEvent):void | |
{ | |
trace('[server] ' + event.message.utf8Data); | |
} | |
protected function onFail(event:WebSocketErrorEvent):void | |
{ | |
trace('[client] connection failed'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment