var
a:array[0100,16] of real;
b:array[0100,12] of real;
n,i,j,k:longint;
c,d,e,f,g,h,x:real;
s:real;
begin
readln(n);
for i:=1 to n do
begin
s:=0;
for j:=1 to 3 do
begin
read(a[i,j]);
s:=s+a[i,j];
end;
a[i,4]:=s;
a[i,5]:=s/3;
b[i,1]:=s;
b[i,2]:=i;
end;
for i:=1 to n-1 do
for j:=1 to n-i do
if b[j,1]<b[j+1,1] then
begin
c:=b[j,1];d:=b[j,2];
b[j,1]:=b[j+1,1];b[j,2]:=b[j+1,2];
b[j+1,1]:=c;b[j+1,2]:=d;
end;
a[0,2]:=1;
a[0,1]:=a[1,1];
for i:=1 to n do
begin
k:=trunc(b[i,2]);
if b[i,1]=b[i-1,1]
then b[i,2]:=b[i-1,2]
else b[i,2]:=i;
a[k,6]:=b[i,2];
end;
for i:=1 to n do
begin
writeln(a[i,1]:0:1,' ',a[i,2]:0:1,' ',a[i,3]:0:1,' ',a[i,4]:0:1,' ',a[i,5]:0:1,' ',a[i,6]:0:0);
end;
end
问题描述:
Activex控件不能例示。 ActiveX 控件“Microsoft Chart
Control 60(sp4)(OLEDB)"不能例示, 因为它需要一个设计时间许可。
解决方法:
1先到C:\WINDOWS\system32目录下看看你的系统里是否已经有了MSADODCocx和MSDATGRDocx这两个文件,没有就去下载;
如果COM组件中还是没有这两个控件,请单击“开始”->“所有程序”->“Microsoft
Visual StudioNET 2003”->“Visual Studio NET
工具”-> “Visual StudioNET 2003 命令提示”输入:regsvr32 msadodcocx和regsvr32 msdatgrdocx,即可以将这两个控件添加到工具箱中
2VC环境中也有了相应的控件选项,
但一添加就提示“Activex控件不能例示”, 然后d出另一个提示:
ActiveX 控件“Microsoft Chart Control
60(sp4)(OLEDB)"不能例示, 因为它需要一个设计时间许可。
若添加控件出现这个问题就进行如下 *** 作:
把内容存为reg文件。(Windows Registry Editor
Version 500reg)双击导入注册表即可。。
Windows Registry Editor Version 500
[HKEY_CLASSES_ROOT\Licenses]
@="Licensing: Copying the keys may be a violation of established
copyrights"
[HKEY_CLASSES_ROOT\Licenses\096EFC40-6ABF-11cf-850C-08002B30345D]
@="knsgigmnmngnmnigthmgpninrmumhgkgrlrk"
[HKEY_CLASSES_ROOT\Licenses\12B142A4-BD51-11d1-8C08-0000F8754DA1]
@="aadhgafabafajhchnbchehfambfbbachmfmb"
[HKEY_CLASSES_ROOT\Licenses\190B7910-992A-11cf-8AFA-00AA00C00905]
@="gclclcejjcmjdcccoikjlcecoioijjcjnhng"
[HKEY_CLASSES_ROOT\Licenses\1F3D5522-3F42-11d1-B2FA-00A0C908FB55]
@="gcfjdjecpchcncdjpdejijgcrdoijjfcieod"
[HKEY_CLASSES_ROOT\Licenses\1FB639E1-771F-11d1-8FD4-00A0C91E29D5]
@="ldaskjeinankjgbnkcejnkrgnkvntkhzkhbtnkste"
[HKEY_CLASSES_ROOT\Licenses\2AC5863D-48B9-490c-ACD3-B7723A1FEB9E]
@="wrtgfdsbvxgfsdyuihjknmvcxgasdwqersdfdfsdyu"
[HKEY_CLASSES_ROOT\Licenses\2c49f800-c2dd-11cf-9ad6-0080c7e7b78d]
@="mlrljgrlhltlngjlthrligklpkrhllglqlrk"
[HKEY_CLASSES_ROOT\Licenses\38911DA0-E448-11D0-84A3-00DD01104159]
@="mcpckchcdchjcjcclidcgcgchdqdcjhcojpd"
[HKEY_CLASSES_ROOT\Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905]
@="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\43478d75-78e0-11cf-8e78-00a0d100038e]
@="imshohohphlmnhimuinmphmmuiminhlmsmsl"
[HKEY_CLASSES_ROOT\Licenses\46D504D7-557F-4C19-A4DD-6605411EF496]
"6A7693BA-3139-41fd-BF3D-299961C965D5"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d1819530400000018000000560053002000500049004400200049006e0066006f00000003660000a80000001000000056a66542c85db014774bffecdc56384e0000000004800000a000000010000000b10a1f771bc4b05515b611500ced2faf10000000263d1b0a183042c62cd7792b75683b4e14000000f30b3972d0fa2871120efa9fba18a3c245e584c2"
@="gknalnanccemnhitviluhawerycnonilwjawreacop"
"CCF5A555-D92E-457b-9235-2B326B64035A"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d1819530400000018000000560053002000500049004400200049006e0066006f00000003660000a8000000100000003311a4ed781bba0eb740244ec6be37e10000000004800000a0000000100000000ef4da56cd76cee7c81f1227b555434f080000000beff2eed562c9a114000000b389c01205cde0aa29234083954295bef840a8c3"
[HKEY_CLASSES_ROOT\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905]
@="gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\4F86BADF-9F77-11d1-B1B7-0000F8753F5D]
@="iplpwpnippopupiivjrioppisjsjlpiiokuj"
[HKEY_CLASSES_ROOT\Licenses\556C75F1-EFBC-11CF-B9F3-00A0247033C4]
@="xybiedobrqsprbijaegcbislrsiucfjdhisl"
[HKEY_CLASSES_ROOT\Licenses\57CBF9E0-6AA7-11cf-8ADB-00AA00C00905]
@="aahakhchghkhfhaamghhbhbhkbpgfhahlfle"
[HKEY_CLASSES_ROOT\Licenses\5BCBC240-27DF-49C1-8C1C-27B8463009A9]
"6A7693BA-3139-41fd-BF3D-299961C965D5"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d18195304000000560000004d006900630072006f0073006f00660074002000560069007300750061006c002000530074007500640069006f00200054007200690061006c002000450064006900740069006f006e0020006400610074006100000003660000a800000010000000c7e1d2e887c57b9814ce91d6c44249ae0000000004800000a00000001000000035f65ddd0c11d820b0b7a72d384e4f08100000006e568533309b0e78012ede394f29e6d81400000080691310641b0c5f28070f7f29fe3acb3d3531a9"
@="iqtdwslvccydcyhxabrcudupqdcalezvinyxwsdjgb"
"CCF5A555-D92E-457b-9235-2B326B64035A"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d18195304000000560000004d006900630072006f0073006f00660074002000560069007300750061006c002000530074007500640069006f00200054007200690061006c002000450064006900740069006f006e0020006400610074006100000003660000a800000010000000157910d280b079e9030212f831ef8dd00000000004800000a00000001000000091b4ddfcf5198d358efe2a227e391200080000008943decdf61422b0140000006eafe0247bfe0b38ba34c5a3fc6106d9bae97edb"
[HKEY_CLASSES_ROOT\Licenses\6000720D-F342-11D1-AF65-00A0C90DCA10]
@="kefeflhlhlgenelerfleheietfmflelljeqf"
[HKEY_CLASSES_ROOT\Licenses\6FB38640-6AC7-11cf-8ADB-00AA00C00905]
@="gdjkokgdldikhdddpjkkekgknesjikdkoioh"
[HKEY_CLASSES_ROOT\Licenses\72E67120-5959-11cf-91F6-C2863C385E30]
@="ibcbbbebqbdbciebmcobmbhifcmciibblgmf"
[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9]
[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9\110]
[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9\110\Retail]
@="sbbcdcprktpjtapmmfdacmupasbhscddncgp"
[HKEY_CLASSES_ROOT\Licenses\743A8267-4958-460e-B757-7110EED3D53C]
@="erwreffdrtetyuiopupoinjxsdfwdxvdgwertdxoui"
[HKEY_CLASSES_ROOT\Licenses\74872840-703A-11d1-A3AF-00A0C90F26FA]
@="mninuglgknogtgjnthmnggjgsmrmgniglish"
[HKEY_CLASSES_ROOT\Licenses\74872841-703A-11d1-A3AF-00A0C90F26FA]
@="klglsejeilmereglrfkleeheqkpkelgejgqf"
[HKEY_CLASSES_ROOT\Licenses\78E1BDD1-9941-11cf-9756-00AA00C00908]
@="yjrjvqkjlqqjnqkjvprqsjnjvkuknjpjtoun"
[HKEY_CLASSES_ROOT\Licenses\7C35CA30-D112-11cf-8E72-00A0C90F26F8]
@="whmhmhohmhiorhkouimhihihwiwinhlosmsl"
[HKEY_CLASSES_ROOT\Licenses\80E80EF0-DBBE-11D0-BCE2-00A0C90DCA10]
@="qijimitpmpnpxplpvjnikpkpqoxjmpkpoivj"
[HKEY_CLASSES_ROOT\Licenses\899B3E80-6AC6-11cf-8ADB-00AA00C00905]
@="wjsjjjlqmjpjrjjjvpqqkqmqukypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\9DF1A470-BA8E-11D0-849C-00A0C90DC8A9]
@="cchcqjejhcgcqcfjpdfcdjkckiqikchcojpd"
[HKEY_CLASSES_ROOT\Licenses\9E799BF1-8817-11cf-958F-0020AFC28C3B]
@="uqpqnqkjujkjjjjqwktjrjkjtkupsjnjtoun"
[HKEY_CLASSES_ROOT\Licenses\A133F000-CCB0-11d0-A316-00AA00688B10]
@="cibbcimbpihbbbbbnhdbeidiocmcbbdbgdoc"
[HKEY_CLASSES_ROOT\Licenses\a8a9f020-b426-11cf-bf3b-00a0d10003fa]
@="eesjgjnekjeeheijrfheiegepftigeljfepi"
[HKEY_CLASSES_ROOT\Licenses\AC0871D0-6ACC-11cf-8ADB-00AA00C00905]
@="knjnpgognginknggsmnnhnjnumvmlngnrlrk"
[HKEY_CLASSES_ROOT\Licenses\AEA64E56-7C97-4a1c-8974-4E0BB4E48FCD]
@="reuikcxsdrecfgfbvnhjkjlpouiyuqwsdrtrtbvgcv"
[HKEY_CLASSES_ROOT\Licenses\B1692F60-23B0-11D0-8E95-00A0C90F26F8]
@="mjjjccncgjijrcfjpdfjfcejpdkdkcgjojpd"
[HKEY_CLASSES_ROOT\Licenses\B1EFCCF0-6AC1-11cf-8ADB-00AA00C00905]
@="qqkjvqpqmqjjpqjjvpqqkqmqvkypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\BC96F860-9928-11cf-8AFA-00AA00C00905]
@="mmimfflflmqmlfffrlnmofhfkgrlmmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\C4145310-469C-11d1-B182-00A0C922E820]
@="konhqhioohihphkouimonhqhvnwiqhhhnjti"
[HKEY_CLASSES_ROOT\Licenses\CDE57A55-8B86-11D0-b3C6-00A0C90AEA82]
@="ekpkhddkjkekpdjkqemkfkldoeoefkfdjfqe"
[HKEY_CLASSES_ROOT\Licenses\CEDD4F80-B43C-11cf-837C-00AA00573EDE]
@=hex(2):67,00,78,00,77,00,61,00,65,00,7a,00,75,00,63,00,66,00,79,00,71,00,70,\
00,77,00,6a,00,67,00,71,00,62,00,63,00,6d,00,74,00,73,00,6e,00,63,00,75,00,\
68,00,77,00,73,00,6e,00,79,00,68,00,69,00,6f,00,68,00,77,00,78,00,7a,00,00,\
00
基于C#的socket编程的TCP异步实现
一、摘要
本篇博文阐述基于TCP通信协议的异步实现。
二、实验平台
Visual Studio 2010
三、异步通信实现原理及常用方法
31 建立连接
在同步模式中,在服务器上使用Accept方法接入连接请求,而在客户端则使用Connect方法来连接服务器。相对地,在异步模式下,服务器可以使用BeginAccept方法和EndAccept方法来完成连接到客户端的任务,在客户端则通过BeginConnect方法和EndConnect方法来实现与服务器的连接。
BeginAccept在异步方式下传入的连接尝试,它允许其他动作而不必等待连接建立才继续执行后面程序。在调用BeginAccept之前,必须使用Listen方法来侦听是否有连接请求,BeginAccept的函数原型为:
BeginAccept(AsyncCallback AsyncCallback, Ojbect state)
参数:
AsyncCallBack:代表回调函数
state:表示状态信息,必须保证state中包含socket的句柄
使用BeginAccept的基本流程是:
(1)创建本地终节点,并新建套接字与本地终节点进行绑定;
(2)在端口上侦听是否有新的连接请求;
(3)请求开始接入新的连接,传入Socket的实例或者StateOjbect的实例。
参考代码:
复制代码
//定义IP地址
IPAddress local = IPAddressParse("1270,0,1");
IPEndPoint iep = new IPEndPoint(local,13000);
//创建服务器的socket对象
Socket server = new Socket(AddressFamilyInterNetwork,SocketTypeStream,ProtocolTypeTcp);
serverBind(iep);
serverListen(20);
serverBeginAccecpt(new AsyncCallback(Accept),server);
复制代码
当BeginAccept()方法调用结束后,一旦新的连接发生,将调用回调函数,而该回调函数必须包括用来结束接入连接 *** 作的EndAccept()方法。
该方法参数列表为 Socket EndAccept(IAsyncResult iar)
下面为回调函数的实例:
复制代码
void Accept(IAsyncResult iar)
{
//还原传入的原始套接字
Socket MyServer = (Socket)iarAsyncState;
//在原始套接字上调用EndAccept方法,返回新的套接字
Socket service = MyServerEndAccept(iar);
}
复制代码
至此,服务器端已经准备好了。客户端应通过BeginConnect方法和EndConnect来远程连接主机。在调用BeginConnect方法时必须注册相应的回调函数并且至少传递一个Socket的实例给state参数,以保证EndConnect方法中能使用原始的套接字。下面是一段是BeginConnect的调用:
Socket socket=new Socket(AddressFamilyInterNetwork,SocketTypeStream,ProtocolTypeTcp)
IPAddress ip=IPAddressParse("127001");
IPEndPoint iep=new IPEndPoint(ip,13000);
socketBeginConnect(iep, new AsyncCallback(Connect),socket);
EndConnect是一种阻塞方法,用于完成BeginConnect方法的异步连接诶远程主机的请求。在注册了回调函数后必须接收BeginConnect方法返回的IASynccReuslt作为参数。下面为代码演示:
复制代码
void Connect(IAsyncResult iar)
{
Socket client=(Socket)iarAsyncState;
try
{
clientEndConnect(iar);
}
catch (Exception e)
{
ConsoleWriteLine(eToString());
}
finally
{
}
}
复制代码
除了采用上述方法建立连接之后,也可以采用TcpListener类里面的方法进行连接建立。下面是服务器端对关于TcpListener类使用BeginAccetpTcpClient方法处理一个传入的连接尝试。以下是使用BeginAccetpTcpClient方法和EndAccetpTcpClient方法的代码:
复制代码
public static void DoBeginAccept(TcpListener listner)
{
//开始从客户端监听连接
ConsoleWriteLine("Waitting for a connection");
//接收连接
//开始准备接入新的连接,一旦有新连接尝试则调用回调函数DoAcceptTcpCliet
listnerBeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpCliet), listner);
}
//处理客户端的连接
public static void DoAcceptTcpCliet(IAsyncResult iar)
{
//还原原始的TcpListner对象
TcpListener listener = (TcpListener)iarAsyncState;
//完成连接的动作,并返回新的TcpClient
TcpClient client = listenerEndAcceptTcpClient(iar);
ConsoleWriteLine("连接成功");
}
复制代码
代码的处理逻辑为:
(1)调用BeginAccetpTcpClient方法开开始连接新的连接,当连接视图发生时,回调函数被调用以完成连接 *** 作;
(2)上面DoAcceptTcpCliet方法通过AsyncState属性获得由BeginAcceptTcpClient传入的listner实例;
(3)在得到listener对象后,用它调用EndAcceptTcpClient方法,该方法返回新的包含客户端信息的TcpClient。
BeginConnect方法和EndConnect方法可用于客户端尝试建立与服务端的连接,这里和第一种方法并无区别。下面看实例:
复制代码
public void doBeginConnect(IAsyncResult iar)
{
Socket client=(Socket)iarAsyncState;
//开始与远程主机进行连接
clientBeginConnect(serverIP[0],13000,requestCallBack,client);
ConsoleWriteLine("开始与服务器进行连接");
}
private void requestCallBack(IAsyncResult iar)
{
try
{
//还原原始的TcpClient对象
TcpClient client=(TcpClient)iarAsyncState;
//
clientEndConnect(iar);
ConsoleWriteLine("与服务器{0}连接成功",clientClientRemoteEndPoint);
}
catch(Exception e)
{
ConsoleWriteLine(eToString());
}
finally
{
}
}
复制代码
以上是建立连接的两种方法。可根据需要选择使用。
32 发送与接受数据
在建立了套接字的连接后,就可以服务器端和客户端之间进行数据通信了。异步套接字用BeginSend和EndSend方法来负责数据的发送。注意在调用BeginSend方法前要确保双方都已经建立连接,否则会出异常。下面演示代码:
复制代码
private static void Send(Socket handler, String data)
{
// Convert the string data to byte data using ASCII encoding
byte[] byteData = EncodingASCIIGetBytes(data);
// Begin sending the data to the remote device
handlerBeginSend(byteData, 0, byteDataLength, 0, new AsyncCallback(SendCallback), handler);
}
private static void SendCallback(IAsyncResult ar)
{
try
{
// Retrieve the socket from the state object
Socket handler = (Socket)arAsyncState;
// Complete sending the data to the remote device
int bytesSent = handlerEndSend(ar);
ConsoleWriteLine("Sent {0} bytes to client", bytesSent);
handlerShutdown(SocketShutdownBoth);
handlerClose();
}
catch (Exception e)
{
ConsoleWriteLine(eToString());
}
}
复制代码
接收数据是通过BeginReceive和EndReceive方法:
复制代码
private static void Receive(Socket client)
{
try
{
// Create the state object
StateObject state = new StateObject();
stateworkSocket = client;
// Begin receiving the data from the remote device
clientBeginReceive(statebuffer, 0, StateObjectBufferSize, 0, new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
ConsoleWriteLine(eToString());
}
}
private static void ReceiveCallback(IAsyncResult ar)
{
try
{
// Retrieve the state object and the client socket
// from the asynchronous state object
StateObject state = (StateObject)arAsyncState;
Socket client = stateworkSocket;
// Read data from the remote device
int bytesRead = clientEndReceive(ar);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far
statesbAppend(EncodingASCIIGetString(statebuffer, 0, bytesRead));
// Get the rest of the data
clientBeginReceive(statebuffer, 0, StateObjectBufferSize, 0, new AsyncCallback(ReceiveCallback), state);
}
else
{
// All the data has arrived; put it in response
if (statesbLength > 1)
{
response = statesbToString();
}
// Signal that all bytes have been received
receiveDoneSet();
}
}
catch (Exception e)
{
ConsoleWriteLine(eToString());
}
}
复制代码
上述代码的处理逻辑为:
(1)首先处理连接的回调函数里得到的通讯套接字client,接着开始接收数据;
(2)当数据发送到缓冲区中,BeginReceive方法试图从buffer数组中读取长度为bufferlength的数据块,并返回接收到的数据量bytesRead。最后接收并打印数据。
除了上述方法外,还可以使用基于NetworkStream相关的异步发送和接收方法,下面是基于NetworkStream相关的异步发送和接收方法的使用介绍。
NetworkStream使用BeginRead和EndRead方法进行读 *** 作,使用BeginWreite和EndWrete方法进行写 *** 作,下面看实例:
复制代码
static void DataHandle(TcpClient client)
{
TcpClient tcpClient = client;
//使用TcpClient的GetStream方法获取网络流
NetworkStream ns = tcpClientGetStream();
//检查网络流是否可读
if(nsCanRead)
{
//定义缓冲区
byte[] read = new byte[1024];
nsBeginRead(read,0,readLength,new AsyncCallback(myReadCallBack),ns);
}
else
{
ConsoleWriteLine("无法从网络中读取流数据");
}
}
public static void myReadCallBack(IAsyncResult iar)
{
NetworkStream ns = (NetworkStream)iarAsyncState;
byte[] read = new byte[1024];
String data = "";
int recv;
recv = nsEndRead(iar);
data = StringConcat(data, EncodingASCIIGetString(read, 0, recv));
//接收到的消息长度可能大于缓冲区总大小,反复循环直到读完为止
while (nsDataAvailable)
{
nsBeginRead(read, 0, readLength, new AsyncCallback(myReadCallBack), ns);
}
//打印
ConsoleWriteLine("您收到的信息是" + data);
}
复制代码
33 程序阻塞与异步中的同步问题
Net里提供了EventWaitHandle类来表示一个线程的同步事件。EventWaitHandle即事件等待句柄,他允许线程通过 *** 作系统互发信号和等待彼此的信号来达到线程同步的目的。这个类有2个子类,分别为AutoRestEevnt(自动重置)和ManualRestEvent(手动重置)。下面是线程同步的几个方法:
(1)Rset方法:将事件状态设为非终止状态,导致线程阻塞。这里的线程阻塞是指允许其他需要等待的线程进行阻塞即让含WaitOne()方法的线程阻塞;
(2)Set方法:将事件状态设为终止状态,允许一个或多个等待线程继续。该方法发送一个信号给 *** 作系统,让处于等待的某个线程从阻塞状态转换为继续运行,即WaitOne方法的线程不在阻塞;
(3)WaitOne方法:阻塞当前线程,直到当前的等待句柄收到信号。此方法将一直使本线程处于阻塞状态直到收到信号为止,即当其他非阻塞进程调用set方法时可以继续执行。
复制代码
public static void StartListening()
{
// Data buffer for incoming data
byte[] bytes = new Byte[1024];
// Establish the local endpoint for the socket
// The DNS name of the computer
// running the listener is "hostcontosocom"
//IPHostEntry ipHostInfo = DnsResolve(DnsGetHostName());
//IPAddress ipAddress = ipHostInfoAddressList[0];
IPAddress ipAddress = IPAddressParse("127001");
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
// Create a TCP/IP socket
Socket listener = new Socket(AddressFamilyInterNetwork,SocketTypeStream, ProtocolTypeTcp);
// Bind the socket to the local
//endpoint and listen for incoming connections
try
{
listenerBind(localEndPoint);
listenerListen(100);
while (true)
{
// Set the event to nonsignaled state
allDoneReset();
// Start an asynchronous socket to listen for connections
ConsoleWriteLine("Waiting for a connection");
listenerBeginAccept(new AsyncCallback(AcceptCallback),listener);
// Wait until a connection is made before continuing
allDoneWaitOne();
}
}
catch (Exception e)
{
ConsoleWriteLine(eToString());
}
ConsoleWriteLine("\nPress ENTER to continue");
ConsoleRead();
}
复制代码
上述代码的逻辑为:
(1)试用了ManualRestEvent对象创建一个等待句柄,在调用BeginAccept方法前使用Rest方法允许其他线程阻塞;
(2)为了防止在连接完成之前对套接字进行读写 *** 作,务必要在BeginAccept方法后调用WaitOne来让线程进入阻塞状态。
当有连接接入后系统会自动调用会调用回调函数,所以当代码执行到回调函数时说明连接已经成功,并在函数的第一句就调用Set方法让处于等待的线程可以继续执行
以上就是关于pascal编程:输入N个同学的语、数、英三科成绩,计算他们的总分与平均分,我自己写的程序实在太乱了。全部的内容,包括:pascal编程:输入N个同学的语、数、英三科成绩,计算他们的总分与平均分,我自己写的程序实在太乱了。、MFC程序中Active X不能例示,怎么办、socket实现过程,具体用的方法;怎么实现异步socket等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)