freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

socketprogramminginc(參考版)

2024-08-25 09:03本頁面
  

【正文】 s all there is to it! Here is how our client looks like Here is how our server looks like That is all there is to the socket programming. 。 (byData)。 } } Here we accept the connection and call WaitForData which in turn calls BeginReceive for the m_socWorker. If we want to send data some data to client we use m_socWorker socket for that purpose like this: Object objData = 。 } catch(ObjectDisposedException) { (0,1,\n OnClientConnection: Socket has been closed\n)。 } } If you look at the above code carefully you will see that its similar to we did in the asynchronous client. First of all the we need to create a listening socket and bind it to a local IP address. Note that we have given Any as the IPAddress (I will explain what it means later), and we have passed the port number as 8221. Next we made a call to Listen function. The 4 is a parameter indicating backlog indicating the maximum length of the queue of pending connections. Next we made a call to BeginAccept passing it a delegate callback. BeginAccept is a nonblocking method that returns immediately and when a client has made requested a connection, the callback routine is called and you can accept the connection by calling EndAccept. The EndAccept returns a socket object which represents the ining connection. Here is the code for the callback delegate: public void OnClientConnect(IAsyncResult asyn) { try { m_socWorker = (asyn)。 = false。 //start listening... (4)。 IPEndPoint ipLocal = new IPEndPoint ( ,8221)。s responsibility is to manage client connections. On the server side there has to be one socket called the Listener socket that listens at a specific port number for client connections. When the client makes a connection, the server needs to accept the connection and then in order for the server to send and receive data from that connected client it needs to talk to that client through the socket that it got when it accepted the connection. The following code illustrates how server listens to the connections and accepts the connection: public Socket m_socListener。 } catch(SocketException se) { ( )。 WaitForData()。 szData = new (chars)。 d = ()。 iRx = (asyn)。 and in the callback function we can get the data like this: public void OnDataReceived(IAsyncResult asyn) { try { CSocketPacket theSockId = (CSocketPacket) 。 = m_socClient。 public byte[] dataBuffer = new byte[1024]。 } The OnConnect function makes a connection to the server and then makes a call to WaitForData. WaitForData creates the callback function and makes a call to BeginReceive passing a global buffer and the callback function. When data arrives the OnDataReceive is called and the m_socClient39。 szData = new (chars)。 d = ()。 iRx = (asyn)。 // now start to listen for any data... m_asynResult = (m_DataBuffer,0,pfnCallBack,null)。 //watch for data ( asynchronously )... WaitForData()。 //create the end point IPEndPoint ipEnd = new IPEndPoint (,iPortNo)。 // get the remote IP address... IPAddress ip = ()。 public Socket m_socClient。 IAsyncResult m_asynResult。s the data? The data is now available in the buffer that you passed as the first parameter while making call to BeginReceive() method . In the following example the data will be available in m_DataBuffer : BeginReceive(m_DataBuffer,0,pfnCallBack,null)。 = + szData。 int charLen = (m_DataBuffer, 0, iRx, chars, 0)。 char[] chars = new char[iRx + 1]。 if ( () ) { int iRx = 0 。 As you can see the callback returns void and is passed in one parameter , IAsyncResult interface , which contains the status of the asynchronous receive operation. The IAsyncResult interface has several properties. The first parameter AsyncState is an object which is same as the last parameter that you passed to BeginReceive(). The second property is AsyncWaitHandle which we will discuss in a moment. The third property indicates whether the receive was really asynchronous or it finished synchronously. The important thing to follow here is that it not necessary for an asynchronous function to always finish asynchronously it can plete immediately if the data is already present. Next parameter is IsComplete which indicates whether the operation has pleted or not
點(diǎn)擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計(jì)相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1