コード例 #1
0
ファイル: Program.cs プロジェクト: jonghough/TekitouSockets
        public static void Main(string[] args)
        {
            Console.WriteLine ("Starting up websocket...");
            Thread thread = null;
            WebsocketController ws = new WebsocketController ();
            ws.Setup ("ws://websocket.org", "80", "/echo", "echo.websocket.org");
            ThreadStart ts = new ThreadStart (() => {
                ws.Connect ((str) => {
                    Console.WriteLine ("OPEN");
                    ws.Send ("Message 1");
                }, (str2) => {
                    Console.WriteLine ("Received");
                    //ws.Send ("Message n");
                }, (str3)=>{ Console.WriteLine(str3); if(thread != null) thread.Join();},
                (str4)=>{ Console.WriteLine(str4); if(thread != null) thread.Join();});
            });

            thread = new Thread (ts);
            thread.Start ();
            while (true) {
                string s = Console.ReadLine ();
                if (!string.IsNullOrEmpty (s))
                    ws.Send (s);
            }
        }
コード例 #2
0
    /// <summary>
    /// Sets up the Websocekt connection with the specified url, port, resource and hostUri.
    /// Intializes connection with server.
    /// </summary>
    /// <param name="url">URL.</param>
    /// <param name="port">Port.</param>
    /// <param name="resource">Resource.</param>
    /// <param name="hostUri">Host URI.</param>
    public void Setup(string url, string port = "80", string resource = null, string hostUri = null)
    {
        _thread = null;

        _websocketController = new WebsocketController ();
        _websocketController.Setup (url, port, resource, hostUri);

        _threadStart = new ThreadStart( ()=>{
            _websocketController.Connect (
                (o) => {lock(_lock){_openStr = o;}},
                (r) => {lock(_lock){_recStr = r;}},
                (c) => {lock(_lock){_closeStr = c;}},
                (e) => {lock(_lock){_errStr = e;}}
            );
        });
        _thread = new Thread (_threadStart);
        _thread.Start ();
    }