看見還有很多人在研究flash的socket,其中經(jīng)常會出現(xiàn)一些問題,所以將我以前寫的一個(gè)程序代碼拿出來給大家參考...
這是c#的代碼,經(jīng)過測試的,本來想把源程序都放上來,可以我用的是vs2005(而且現(xiàn)在又壞了,系統(tǒng)出問題了),下面是程序的主要源代碼,不包含一些自動生成的代碼.這些代碼是根據(jù)一個(gè)開源的C#socket程序改編的,而且我已經(jīng)寫了比較詳細(xì)的注釋了,如果你看了這些代碼還是發(fā)現(xiàn)有問題,可以向我索取完整的源程序:
[1b]把源文件傳上來,大家可以下載(gmail又打不開了,不能給留email的同學(xué)發(fā)了,自己下載吧):

點(diǎn)擊下載此文件
[/1b]
//--------------------------------
//---------------------------------------------------------------------------------------------------------------
//form1.cs
using System;
using System.IO;
using System.Drawing;
using System.Collections;//ArrayList引用到這個(gè)命名空間的類
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace ChatServer//服務(wù)器端命名空間
{
?///
?/// Form1 的摘要說明。
?///
?public class Form1 : System.Windows.Forms.Form
?{
??private int listenport = 9050;//監(jiān)聽端口
??private TcpListener listener;//監(jiān)聽者
??private ArrayList clients;//所有的client
??private Thread processor;//處理線程
??private Socket clientsocket;//client套接字
??private Thread clientservice;//client的服務(wù)
??private System.Windows.Forms.ListBox lbClients;
??private System.Windows.Forms.Label label1;//顯示在線人員的List控件
??private TcpClient tclient;
??private NetworkStream ns;
??private System.Windows.Forms.Button button1;
??///
??/// 必需的設(shè)計(jì)器變量。
??///
??private System.ComponentModel.Container components = null;
??public Form1()
??{
???//
???// Windows 窗體設(shè)計(jì)器支持所必需的
???//
???InitializeComponent();
???Thread.CurrentThread.IsBackground = true;
???//
???// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
???//
???clients = new ArrayList();//新建一個(gè)ArrayList類型用以存儲所有的client
???processor = new Thread(new ThreadStart(StartListening));//新建一個(gè)處理線程
???processor.Start();//線程開始
???//
??}
??///
??/// 清理所有正在使用的資源。
??///
??protected override void Dispose( bool disposing )
??{
??
????int c = clients.Count;
????for(int n=0; n
{
?????components.Dispose();
????}
???}
???base.Dispose( disposing );
??}
??///
??/// 開始監(jiān)聽
??///
??private void StartListening()
??{
???IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
???//IPAddress ipAddress = IPAddress.Parse("192.168.0.132");
???
???label1.Text=ipAddress.ToString();
???IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, listenport);
???listener = new TcpListener(ipLocalEndPoint);
???listener.Start();
???while (true)
本文轉(zhuǎn)自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/869.html
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
