using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
public class mySocket
{
private static Socket connectSocket(string server, int port)
{
Socket s = null;
IPHostEntry iphe = null;
try
{
// Get host related information.
iphe = Dns.Resolve(server);
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception to be thrown if the host IP Address is not compatible with the address family
// (typical in the IPv6 case).
foreach(IPAddress ipad in iphe.AddressList)
{
IPEndPoint ipe = new IPEndPoint(ipad, port);
Socket tmpS =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
// This method requests the home page content for the passed server.
// It displays the number of bytes received and the page content.
private static string socketSendReceive(string server, int port)
{
//Set up variables and String to write to the server.
Encoding ASCII = Encoding.ASCII;
string Get = "GET / HTTP/1.1\r\nHost: " + server +
"\r\nConnection: Close\r\n\r\n";
Byte[] ByteGet = ASCII.GetBytes(Get);
Byte[] RecvBytes = new Byte[256];
String strRetPage = null;
// Create a socket connection with the specified server and port.
Socket s = connectSocket(server, port);
if (s == null)
return ("Connection failed");
// Send request to the server.
s.Send(ByteGet, ByteGet.Length, 0);
// Receive the server home page content.
Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
// Read the first 256 bytes.
strRetPage = "Default HTML page on " + server + ":\r\n";
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
public static void Main(string[] args)
{
string host;
int port = 80;
if (args.Length == 0)
// If no server name is passed as argument to this program, use the current
// host name as default.
host = Dns.GetHostName();
else
host = args[0];
set ASPpush = Server.CreateObject("ASPpush.page")
Do While Response.IsClientConnected
'================================
'在这里修改或自定义要执行的ASP代码
Response.Write "我晕...<br>"
'================================
Response.Flush
ASPpush.wait 100 '后面的数字以毫秒为单位(1000毫秒=1秒),指定推送的速度
Loop
set ASPpush=nothing
%>