二,IIS支援設定,參考此文
三server side pacakge,連結在此
工作原理影音,請參考此連結 ,第三段中間開始,5707站台的程式集是asp.net4.5 +管線整合模式
四,如果你要用非網頁型態的client的話,用以下的程式碼:
========================================
using System;
using System.Linq;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace WebSocketClient
{
class Program
{
static void Main(string[] args)
{
new Program().Start().Wait();
}
public async Task Start()
{
Console.Write("Name please: ");
string name = Console.ReadLine();
Console.Write("Connecting....");
var cts = new CancellationTokenSource();
var socket = new ClientWebSocket();
string wsUri = string.Format("ws://10.10.10.11:5707/WebSocketsServer2.ashx?chatName={0}", name);
await socket.ConnectAsync(new Uri(wsUri), cts.Token);
Console.WriteLine(socket.State);
Task.Factory.StartNew(
async () =>
{
var rcvBytes = new byte[128];
var rcvBuffer = new ArraySegment<byte>(rcvBytes);
while (true)
{
WebSocketReceiveResult rcvResult = await socket.ReceiveAsync(rcvBuffer, cts.Token);
byte[] msgBytes = rcvBuffer.Skip(rcvBuffer.Offset).Take(rcvResult.Count).ToArray();
string rcvMsg = Encoding.UTF8.GetString(msgBytes);
Console.WriteLine("Received: {0}", rcvMsg);
}
}, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
while (true)
{
var message = Console.ReadLine();
if (message == "Bye")
{
cts.Cancel();
return;
}
byte[] sendBytes = Encoding.UTF8.GetBytes(message);
var sendBuffer = new ArraySegment<byte>(sendBytes);
await socket.SendAsync(sendBuffer, WebSocketMessageType.Text, endOfMessage: true, cancellationToken: cts.Token);
}
}
}
}
========================================
以上,加油了
沒有留言:
張貼留言