i am building a server client application using WebsocketServer(0.6)
my problem is when i run this code on my win7 64 bit laptop the in client and server connection open event is called and no messages are exchanged, but when i run same code on win7 32bit code runs perfectly , my question is is i'm doing something wrong or i have to use some other library for 64bit os?next question is can i host it on a websiteor WCF somehow ?
the server portion is a dektop app
here is the code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private List<WebSocketSession> m_Sessions = new List<WebSocketSession>();
private List<WebSocketSession> m_SecureSessions = new List<WebSocketSession>();
WebSocketServer WebSocket;
private void button1_Click(object sender, EventArgs e)
{
WebSocket = new WebSocketServer();
WebSocket.Setup(new RootConfig(),
new ServerConfig
{
Name = "SuperWebSocket",
Ip = "Any",
Port = 3202,
Mode = SocketMode.Async
}, SocketServerFactory.Instance);
WebSocket.NewDataReceived += new SuperWebSocket.SessionEventHandler<SuperWebSocket.WebSocketSession, byte[]>(wss_NewDataReceived);
WebSocket.NewMessageReceived += new SuperWebSocket.SessionEventHandler<SuperWebSocket.WebSocketSession, string>(wss_NewMessageReceived);
WebSocket.NewSessionConnected += new SuperWebSocket.SessionEventHandler<SuperWebSocket.WebSocketSession>(wss_NewSessionConnected);
WebSocket.SessionClosed += new SessionEventHandler<WebSocketSession, SuperSocket.SocketBase.CloseReason>(wss_SessionClosed);
WebSocket.Start();
}
void wss_SessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason e)
{
textBox2.Invoke((Action)(() => textBox2.AppendText("closed")));
}
void wss_NewSessionConnected(SuperWebSocket.WebSocketSession session)
{
textBox2.Invoke((Action)(() => textBox2.AppendText("opened")));
}
void wss_NewMessageReceived(SuperWebSocket.WebSocketSession session, string e)
{
textBox2.Invoke((Action)(() => textBox2.AppendText(e)));
}
void wss_NewDataReceived(SuperWebSocket.WebSocketSession session, byte[] e)
{
textBox2.Invoke((Action)(() => textBox2.AppendText("data recived")));
}
private void button2_Click(object sender, EventArgs e)
{
foreach (WebSocketSession wss in WebSocket.GetAllSessions())
{
wss.SendResponse("hello from server");
}
}
}
and client is html page
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function WebSocketTest() {
if ("WebSocket" in window) {
alert("WebSocket is supported by your Browser!");
var ws = new WebSocket("ws://localhost:3202");
ws.onerror = function () {
alert("error");
}
ws.onopen = function () {
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
alert("Message is received..." + received_msg);
};
ws.onclose = function () {
alert("Connection is closed...");
};
}
else {
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</head>
<body>
<div id="sse">
<a href="java<!-- no -->script:WebSocketTest()">Run WebSocket</a>
</div>
</body>
</html>