Opened event didnt fire!

Feb 22, 2013 at 1:29 PM
Edited Feb 22, 2013 at 1:30 PM
Hello and sorry for repeating that topic, but nothing workt for me. I trasformed the example https://github.com/abarth500/websocket4net-example into a WindowsFormsproject, and tested it with two websocket servers. One of them was the alchemy websocket server. Iam always get a good handshake. After this the servers say that they listen to the client. The connected event will not fired. Otherevents like Closed or Error will fired. I set breakpoints for checking it. Here is my code:
using System;
using System.Windows.Forms;

using WebSocket4Net;

namespace WebSocketClient {
  public partial class Form1 : Form {
    private const string ServerUrl = "ws://127.0.0.1:8181";
    private WebSocket _websocket;
    private bool _isConnected = false;

    public Form1(){
      InitializeComponent();
      btnSend.Enabled = false;

      _websocket = new WebSocket(ServerUrl);
      _websocket.Opened += new EventHandler(OnWebsocketOpened);
      _websocket.Closed += new EventHandler(OnWebsocketClosed);
      _websocket.DataReceived += new EventHandler<DataReceivedEventArgs>(OnWebsocketDataReceived);
      _websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(OnWebsocketError);
      _websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(OnWebsocketMessageReceived);

      _websocket.Open();

      tbxMessage.Focus();
    }

    void OnWebsocketMessageReceived(object sender, MessageReceivedEventArgs e) {
      Action action = new Action(delegate {
        tbxChatHistory.Text += e.Message + Environment.NewLine;
        tbxChatHistory.SelectionStart = tbxChatHistory.Text.Length;
        tbxChatHistory.ScrollToCaret();  
      });
      if(InvokeRequired) {
        BeginInvoke(action);
      }
      else {
        action.Invoke();
      }
    }

    private void OnWebsocketOpened(object sender, EventArgs e){
      _isConnected = true;
      Action action = new Action(delegate {
        btnSend.Enabled = true;
        tbxChatHistory.Text += "[open]"+Environment.NewLine;
      });
      if(InvokeRequired) {
        BeginInvoke(action);
      }
      else {
        action.Invoke();
      }
    }

    void OnWebsocketError(object sender, SuperSocket.ClientEngine.ErrorEventArgs e) {
      Action action = new Action(delegate {
        tbxChatHistory.Text += "[error] " + e.Exception.Message + Environment.NewLine;
        btnSend.Enabled = false;
      });
      if(InvokeRequired) {
        BeginInvoke(action);
      }
      else {
        action.Invoke();
      }
    }

    void OnWebsocketDataReceived(object sender, DataReceivedEventArgs e) {
      throw new NotImplementedException();
    }

    private void OnWebsocketClosed(object sender, EventArgs e){
      Action action = new Action(delegate {
                                   tbxChatHistory.Text += "[closed]" + Environment.NewLine;
                                   btnSend.Enabled = false;
                                 });
      if(InvokeRequired){
        BeginInvoke(action);
      }
      else{
        action.Invoke();
      }
    }

    private void SendMessage(){
      if(_isConnected){
        Action action = new Action(delegate {
          _websocket.Send(tbxMessage.Text + Environment.NewLine);
        });
        if(InvokeRequired) {
          BeginInvoke(action);
        }
        else {
          action.Invoke();
        }
      }
    }

    private void btnSend_Click(object sender, EventArgs e) {
      SendMessage();
    }

    private void tbxMessage_KeyDown(object sender, KeyEventArgs e) {
      if(e.KeyCode == Keys.Enter){
        SendMessage();
      }
    }
  }
}
I dont know if it is a problem of the client or a problem of the server? Where can i find a example serverfor testing the client?

Greetings
karsten
Coordinator
Feb 23, 2013 at 3:07 AM
Did you verify the connectability of the websocket server by telnet?
Feb 25, 2013 at 8:37 AM
Edited Feb 25, 2013 at 8:38 AM
kerryjiang wrote:
Did you verify the connectability of the websocket server by telnet?
I only use localhost for my connection.
Coordinator
Feb 25, 2013 at 12:10 PM
I mean you should verify the server is started correctly.

Sent from my Windows Phone

From: karsten_kunz
Sent: 2/25/2013 3:37
To: kerry-jiang@hotmail.com
Subject: Re: Opened event didnt fire! [websocket4net:434116]

From: karsten_kunz

kerryjiang wrote:
Did you verify the connectability of the websocket server by telnet?
I only use localhost for my connection.