win7 64bit的SuperWebSocket [英] SuperWebSocket in win7 64bit

查看:79
本文介绍了win7 64bit的SuperWebSocket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebsocketServer(0.6)构建服务器客户端应用程序

我的问题是当我在win7 64位笔记本电脑上运行此代码时,在客户端和服务器连接打开事件被调用且没有消息交换,但当我在win7上运行相同的代码32位代码运行完美,我的问题是我做错了什么或我必须使用其他库64位操作系统?接下来的问题是我可以在网站或WCF以某种方式托管它?



服务器部分是dektop应用程序



这里是代码

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)
        {
           // ((WebSocketSession)WebSocket.GetAllSessions()[0]).SendResponse("");
            foreach (WebSocketSession wss in WebSocket.GetAllSessions())
            {
                wss.SendResponse("hello from server");
            }
        }      
    }





和客户端是html页面





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!");
            // Let us open a web socket
            var ws = new WebSocket("ws://localhost:3202");
            ws.onerror = function () {
                alert("error");
            }
            ws.onopen = function () {
                // Web Socket is connected, send data using send()
                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 () {
                // websocket is closed.
                alert("Connection is closed...");
            };
           
        }
        else {
            // The browser doesn't support WebSocket
            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>

推荐答案

这可能有效:在VS中2008转到项目,属性,标签构建:将平台目标更改为x86,



告诉我。
This may work: In VS 2008 goto Project, Properties, Tab Build: Change Platform Target to x86,

Let me know.


在客户端代码中,ws变量应该是全局的。现在它是该函数的本地函数,并在函数执行后被删除。
In the client code, the ws variable should be global. Now it's local to that function and gets deleted after the function is executed.


你必须使用版本4.0的supersocket dll
u have to use supersocket dll of version 4.0


这篇关于win7 64bit的SuperWebSocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆