All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
初学,ASP.NET,AJAX,(二):小试,ScriptManager_[Asp.Net教程]
ASP.NET2.0数据库入门之SqlDataSource_[Asp.Net教程]
Delphi在状态栏中显示检查框实例
asp.net2.0里用Calendar控件做带节日提示的日历_[Asp.Net教程]
SQL数据操作基础(初级)5_mssql学习_编程技术
PHP开发中常用的一些函数_[PHP教程]
Sqlserver常用函数例子说明_[SQL Server教程]
入门学习之透析PHP的配置文件php.ini_php资料_编程技术
aspx页面弹出窗口代码大全_[Asp.Net教程]
FCKEditor在Asp.net的安装_[Asp.Net教程]
Reading number is top 10 pictures
Players in the eyes of a perfect love2
30 beautiful school beauty4
漂亮的跳舞妹妹2
赵惟依写真2
西游日记3
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line2
Beauty ZhiHuiLin1
Forced sex girl living abroad2
奇趣的世界记录3
Most cow mistress ZhaoGongXia face exposure
Download software ranking
Call Of Duty2
软件工程思想
网络管理员第三版
Unix video tutorial10
实战黑客不求人
Take off clothes to survival
Tram sex maniac 2 (H) rar bag7
The Bermuda triangle3
Boxer vs Yellow4
Detective task-the top secret prostitution files
delv published in(发表于) 2014/1/24 9:02:49 Edit(编辑)
Asp.net,Socket,客户端(发送和接收数据,)_[Asp.Net教程]

Asp.net,Socket,客户端(发送和接收数据,)_[Asp.Net教程]

Asp.net Socket 客户端(发送和接收数据 )_[Asp.Net教程]

//############################################
版权声明:
文章内容为本站编辑,创作.你可以任意转载、发布、使用但请务必明文标注文章原始出处及本声明
http://www.opent.cn 作者:浪淘沙
############################################/



/***************************************
* 对象名称: SocketObj
* 功能说明: 远程发送与接收
* 试用示例:
* using EC; //引用空间名
* string url = "218.75.111.74"; // URL也可以是(www.baidu.com)这种形式
* int port = 8000; //端口
* string SendStr = "domainname\n"; //组织要发送的字符串
* SendStr += "check\n";
* SendStr += "entityname:domains\n";
* SendStr += "domainname:" + this.TextBox1.Text + "\n";
* SendStr += ".\n";
* EBSocketObj o = new SocketObj(); //创建新对象
* o.Connection(url, port); //打开远程端口
* o.Send(SendStr); //发送数据
* Response.Write(o.Recev()); //接收数据
* o.Dispose(); //销毁对象

**********************************************/

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace EC
{
///
/// Socket 远程发送与接收
///

public class SocketObj
{
private NetworkStream ns;
private bool _alreadyDispose = false;

#region 构造与释构
public EBSocketObj()
{
//
// TOD 在此处添加构造函数逻辑
//
}
public EBSocketObj(string url, int port)
{
Connection(url, port);
}
~EBSocketObj()
{
Dispose();
}
protected virtual void Dispose(bool isDisposing)
{
if (_alreadyDispose) return;
if (isDisposing)
{
if (ns != null)
{
try
{
ns.Close();
}
catch (Exception E) { }
ns.Dispose();
}
}
_alreadyDispose = true;
}
#endregion

#region IDisposable 成员

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion

#region 打开端口
///
/// 打开端口
///

/// URL或者:IP地址
///
///
public virtual void Connection(string url, int port)
{
if (url == null || url == "") return;
if (port < 0) return;
if (port.ToString()==string.Empty) port = 80;
TcpClient tcp = null;
try
{
tcp = new TcpClient(url, port);
}
catch (Exception E)
{
throw new Exception("Can't connection:" + url);
}
this.ns = tcp.GetStream();
}
#endregion

#region 发送Socket
///
/// 发送Socket
///

///
///
///
public virtual bool Send(string message)
{
if (ns == null) return false;
if (message == null || message == "") return false;
byte[] buf = Encoding.ASCII.GetBytes(message);
try
{
ns.Write(buf, 0, buf.Length);
}
catch (Exception E)
{
throw new Exception("Send Date Fail!");
}
return true;
}
#endregion

#region 收取信息
///
/// 收取信息
///

///
///
public string Recev()
{
if (ns == null) return null;
byte[] buf = new byte[4096];
int length = 0;
try
{
length = ns.Read(buf, 0, buf.Length);
}
catch (Exception E)
{
throw new Exception("Receive data fail!");
}
return Encoding.ASCII.GetString(buf, 0, length);
}
#endregion

}
}

Asp.net Socket 客户端(发送和接收数据 )







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.