| ²é¿´: 205 | »Ø¸´: 0 | |||
| µ±Ç°Ö÷ÌâÒѾ´æµµ¡£ | |||
zsgllyľ³æ (ÖøÃûдÊÖ)
|
[½»Á÷]
ʹÓÃCSockets½øÐÐÎļþ´«ËÍ
|
||
|
ÕâÊÇÒ»¶ÔʵÏÖÔÚÁ½Ì¨¼ÆËã»ú¼ä´«ËÍÎļþµÄº¯Êý,ÎÒûÓп´µ½¹ýʹÓÃCSocket½øÐÐÎļþ´«Ë͵ĴúÂë,Ï£Íû´Ë´úÂë¶ÔÄãÓÐÓÃ.´úÂëÖаüº¬Á½¸öº¯Êý,µÚÒ»¸öÓÃÓÚ·þÎñÆ÷¶Ë,µÚ¶þ¸öÓÃÓÚ¿Í»§¶Ë. ÐèҪ˵Ã÷µÄÊDZ¾ÎÄÌṩµÄ·½·¨²¢²»ÊÊÓÃÓÚ´óÐÍÎļþµÄ´«ËÍ. ÏÂÃæ¸ø³ö·þÎñÆ÷¶Ë´úÂë:void SendFile() { #define PORT 34000 /// Select any free port you wish AfxSocketInit(NULL); CSocket sockSrvr; sockSrvr.Create(PORT); // Creates our server socket sockSrvr.Listen(); // Start listening for the client at PORT CSocket sockRecv; sockSrvr.Accept(sockRecv); // Use another CSocket to accept the connection CFile myFile; myFile.Open("C:\\ANYFILE.EXE", CFile::modeRead | CFile::typeBinary); int myFileLength = myFile.GetLength(); // Going to send the correct File Size sockRecv.Send(&myFileLength, 4); // 4 bytes long byte* data = new byte[myFileLength]; myFile.Read(data, myFileLength); sockRecv.Send(data, myFileLength); //Send the whole thing now myFile.Close(); delete data; sockRecv.Close(); } ÒÔÏÂÊǿͻ§¶Ë´úÂë void GetFile() { #define PORT 34000 /// Select any free port you wish AfxSocketInit(NULL); CSocket sockClient; sockClient.Create(); // "127.0.0.1" is the IP to your server, same port sockClient.Connect("127.0.0.1", PORT); int dataLength; sockClient.Receive(&dataLength, 4); //Now we get the File Size first byte* data = new byte[dataLength]; sockClient.Receive(data, dataLength); //Get the whole thing CFile destFile("C:\\temp\\ANYFILE.EXE", CFile::modeCreate | CFile::modeWrite | CFile::typeBinary); destFile.Write(data, dataLength); // Write it destFile.Close(); delete data; sockClient.Close(); } ×îºÃÈ·ÈÏ·þÎñÆ÷¶Ëº¯ÊýÔÚ¿Í»§¶Ëº¯Êý֮ǰÔËÐÐ,±¾ÎĵĴúÂë¿ÉÒÔ·½±ãµØÌí¼Óµ½¹¤³ÌÖÐ,½â¾ö·þÎñÆ÷/¿Í»§Ä£ÐÍÖеÄÎļþ´«ËÍÎÊÌâ. ¸Ðл´ó¼Ò! [ Last edited by »ÃÓ°ÎÞºÛ on 2006-11-29 at 07:45 ] |
» ²ÂÄãϲ»¶
08¹¤Ñ§µ÷¼Á
ÒѾÓÐ16È˻ظ´
0703»¯Ñ§µ÷¼Á£¬Çóµ¼Ê¦ÊÕ
ÒѾÓÐ7È˻ظ´
0854AI CV·½ÏòÕÐÊÕµ÷¼Á
ÒѾÓÐ3È˻ظ´
Çóµ÷¼Á323²ÄÁÏÓ뻯¹¤
ÒѾÓÐ3È˻ظ´
ÉúÎïѧѧ˶Çóµ÷¼Á
ÒѾÓÐ9È˻ظ´
289Çóµ÷¼Á
ÒѾÓÐ8È˻ظ´
07»¯Ñ§280·ÖÇóµ÷¼Á
ÒѾÓÐ5È˻ظ´
300·Ö£¬²ÄÁÏ£¬Çóµ÷¼Á£¬Ó¢Ò»Êý¶þ
ÒѾÓÐ4È˻ظ´
¡¾¿¼Ñе÷¼Á¡¿»¯Ñ§×¨Òµ 281·Ö£¬Ò»Ö¾Ô¸ËÄ´¨´óѧ£¬³ÏÐÄÇóµ÷¼Á
ÒѾÓÐ16È˻ظ´
0854µç×ÓÐÅÏ¢Çóµ÷¼Á
ÒѾÓÐ7È˻ظ´














»Ø¸´´ËÂ¥