您的位置:首页 > 其它

稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室

2008-12-22 08:40 501 查看
[索引页]

[源码下载]

[align=center]稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室[/align]

作者:webabcd

介绍

Silverlight 2.0 Socket通信。开发一个多人聊天室

服务端:实例化Socket, 绑定, 监听, 连接, 接收数据, 发送数据

客户端:实例化Socket, 指定服务端地址, 连接, 接收数据, 发送数据

在线DEMO

/article/4589581.html

示例

1、Policy服务(向客户端发送策略文件的服务)

clientaccesspolicy.xml

<?xml version="1.0" encoding ="utf-8"?>

<access-policy>

<cross-domain-access>

<policy>

<allow-from>

<domain uri="*" />

</allow-from>

<grant-to>

<socket-resource port="4502-4534" protocol="tcp" />

</grant-to>

</policy>

</cross-domain-access>

</access-policy>

Main.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net.Sockets;

using System.IO;

using System.Net;

namespace PolicyServer

2、Socket服务端(聊天室的服务端)

ClientSocketPacket.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace SocketServer

Main.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net.Sockets;

using System.Net;

using System.Threading;

using System.IO;

namespace SocketServer

<UserControl x:Class="Silverlight20.Communication.SocketClient"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<StackPanel HorizontalAlignment="Left" Width="600" Margin="5" Background="Gray">

<ScrollViewer x:Name="scrollChat" Height="400" VerticalScrollBarVisibility="Auto" Background="White" Margin="10">

<TextBlock x:Name="txtChat" TextWrapping="Wrap" />

</ScrollViewer>

<StackPanel Orientation="Horizontal" Margin="5">

<TextBox x:Name="txtName" Margin="5" Width="100" />

<TextBox x:Name="txtInput" Margin="5" Width="400" KeyDown="txtInput_KeyDown" />

<Button x:Name="btnSend" Margin="5" Width="60" Content="Send" Click="btnSend_Click"/>

</StackPanel>

</StackPanel>

</UserControl>

SocketClient.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Net.Sockets;

using System.Text;

namespace Silverlight20.Communication

OK

[源码下载]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐