稳扎稳打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
[源码下载]
[源码下载]
[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
[源码下载]
相关文章推荐
- 稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室
- 上接稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室
- 稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室
- 稳扎稳打Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室
- 2.0通信之Socket, 开发一个多人聊天室
- 与众不同 windows phone (30) - Communication(通信)之基于 Socket TCP 开发一个多人聊天室
- 与众不同 windows phone (31) - Communication(通信)之基于 Socket UDP 开发一个多人聊天室
- 与众不同 windows phone (31) - Communication(通信)之基于 Socket UDP 开发一个多人聊天室
- 与众不同 windows phone (30) - Communication(通信)之基于 Socket TCP 开发一个多人聊天室
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp
- 稳扎稳打Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service)
- 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器
- 稳扎稳打Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据
- 稳扎稳打Silverlight(21) - 2.0通信之WebRequest和WebResponse, 对指定的URI发出请求以及接收响应
- 稳扎稳打Silverlight(53) - 4.0通信之对WCF NetTcpBinding的支持, 在Socket通信中通过HTTP检索策略文件, HTTP请求中的ClientHttp和BrowserHttp