[索引页]
[源码下载]
稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室
作者:webabcd
介绍
Silverlight 2.0 Socket通信。开发一个多人聊天室
服务端:实例化Socket, 绑定, 监听, 连接, 接收数据, 发送数据
客户端:实例化Socket, 指定服务端地址, 连接, 接收数据, 发送数据
在线DEMO
http://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.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
}
3、Socket客户端(聊天室的客户端)
SocketClient.xaml
<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
[源码下载]
相关文章:
-
2021-06-15
-
2021-08-24
-
2021-08-05
-
2021-12-12
-
2022-03-02
-
2021-09-16
-
2021-10-07
-
2021-07-23