2017-05-25 149 views
0

我發現網上的這兩個示例是socket.io應用程序和第二個是c# form application這是基於服務器客戶端的應用程序,它可以正常工作,但是當我嘗試建立c#表單應用程序和socket.io應用程序我看不到從c#表單應用程序發送的消息。我運行socket.io應用程序作爲我的服務器和c#窗體應用程序作爲我的客戶端,並在兩側使用相同的端口號,並給予我的服務器的IP到c#在客戶部分提交表格申請。我認爲它不會收到數據,因爲index.html首先要求提供暱稱,然後顯示該用戶發送的消息。我該如何處理,以便首次收到的消息將被視爲用戶名,然後剩餘的消息將顯示在網頁上用戶名。我需要用戶名,因爲我想從index.html發送消息到C#表單應用程序also.Please幫助我試圖實現這一點從三週。謝謝。如何發送消息從c#表單應用程序到Socket.io應用程序

回答

0
C# supports TCP sockets: 
1) You must need a IpAddress and Port number to connect. 
    Socket socket = new 
    System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, 
         System.Net.Sockets.SocketType.Stream, 
    System.Net.Sockets.ProtocolType.Tcp); 
     try 
     { 
      byte[] bytes = new byte[256]; 

      IPAddress ipAdd = System.Net.IPAddress.Parse(ipAddress); 
      IPEndPoint remoteEP = new IPEndPoint(ipAdd, port); 
      if (Session["IsPortConnected"] == null) 
      { 
       socket.Connect(remoteEP); 
      } 
     } 


If this answer helped you please mark it correct. 
+0

我已經給我的服務器IP地址形成應用程序。問題是index.html頁面不直接顯示消息,如果暱稱沒有輸入,我不希望 –

相關問題