資源簡介
所傳文檔為MFC的SOCKET協議與HTML5里的WEBSOCKET協議之間的通信連接,發送和讀寫都沒有什么問題,另外附帶有一個C#的websocket庫,庫不是開源的,網上也有詳細介紹,如果想用C++這塊的可以看看,有什么問題可以直接留言,看到后會盡快幫忙解答。
代碼片段和文件信息
/*?
???base64.cpp?and?base64.h
???Copyright?(C)?2004-2008?René?Nyffenegger
???This?source?code?is?provided?‘as-is‘?without?any?express?or?implied
???warranty.?In?no?event?will?the?author?be?held?liable?for?any?damages
???arising?from?the?use?of?this?software.
???Permission?is?granted?to?anyone?to?use?this?software?for?any?purpose
???including?commercial?applications?and?to?alter?it?and?redistribute?it
???freely?subject?to?the?following?restrictions:
???1.?The?origin?of?this?source?code?must?not?be?misrepresented;?you?must?not
??????claim?that?you?wrote?the?original?source?code.?If?you?use?this?source?code
??????in?a?product?an?acknowledgment?in?the?product?documentation?would?be
??????appreciated?but?is?not?required.
???2.?Altered?source?versions?must?be?plainly?marked?as?such?and?must?not?be
??????misrepresented?as?being?the?original?source?code.
???3.?This?notice?may?not?be?removed?or?altered?from?any?source?distribution.
???René?Nyffenegger?rene.nyffenegger@adp-gmbh.ch
*/
#include?“StdAfx.h“
#include?“base64.h“
#include?
static?const?std::string?base64_chars?=?
?????????????“ABCDEFGHIJKLMNOPQRSTUVWXYZ“
?????????????“abcdefghijklmnopqrstuvwxyz“
?????????????“0123456789+/“;
static?inline?bool?is_base64(unsigned?char?c)?{
??return?(isalnum(c)?||?(c?==?‘+‘)?||?(c?==?‘/‘));
}
std::string?base64_encode(unsigned?char?const*?bytes_to_encode?unsigned?int?in_len)?{
??std::string?ret;
??int?i?=?0;
??int?j?=?0;
??unsigned?char?char_array_3[3];
??unsigned?char?char_array_4[4];
??while?(in_len--)?{
????char_array_3[i++]?=?*(bytes_to_encode++);
????if?(i?==?3)?{
??????char_array_4[0]?=?(char_array_3[0]?&?0xfc)?>>?2;
??????char_array_4[1]?=?((char_array_3[0]?&?0x03)?<4)?+?((char_array_3[1]?&?0xf0)?>>?4);
??????char_array_4[2]?=?((char_array_3[1]?&?0x0f)?<2)?+?((char_array_3[2]?&?0xc0)?>>?6);
??????char_array_4[3]?=?char_array_3[2]?&?0x3f;
??????for(i?=?0;?(i?<4)?;?i++)
????????ret?+=?base64_chars[char_array_4[i]];
??????i?=?0;
????}
??}
??if?(i)
??{
????for(j?=?i;?j?3;?j++)
??????char_array_3[j]?=?‘\0‘;
????char_array_4[0]?=?(char_array_3[0]?&?0xfc)?>>?2;
????char_array_4[1]?=?((char_array_3[0]?&?0x03)?<4)?+?((char_array_3[1]?&?0xf0)?>>?4);
????char_array_4[2]?=?((char_array_3[1]?&?0x0f)?<2)?+?((char_array_3[2]?&?0xc0)?>>?6);
????char_array_4[3]?=?char_array_3[2]?&?0x3f;
????for?(j?=?0;?(j???????ret?+=?base64_chars[char_array_4[j]];
????while((i++?3))
??????ret?+=?‘=‘;
??}
??return?ret;
}
std::string?base64_decode(std::string?const&?encoded_string)?{
??size_t?in_len?=?encoded_string.size();
??int?i?=?0;
??int?j?=?0;
??int?in_?=?0;
??unsigned?char?char_array_4[4]?char_array_3[3];
??std::string?ret;
??while?(in_len--?&&?(?encoded_string[in_]?!=?‘=‘)?&&?is_base64(encoded_string[in_]))?{
????char_array_4[i++]?=?encoded_string[in_];?in_++;
????if?(i?==4)?{
??????for?(i?=?0;?i?<4;?i++)
????????char_array_4[i]?=?base64_chars.find(char_array_4[i]);
??????char_array_3[0]?=?(char_array_4[0]?<2)?+?((
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????238080??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\Debug\TCPSever.exe
?????文件????2259124??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\Debug\TCPSever.ilk
?????文件????8687616??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\Debug\TCPSever.pdb
?????文件???????3760??2012-11-28?11:28??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\ba
?????文件????????136??2012-03-18?14:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\ba
?????文件?????164944??2016-11-17?15:35??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\ba
?????文件??????19422??2016-11-17?15:35??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\sha1.obj
?????文件?????932828??2016-11-17?09:54??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\stdafx.obj
?????文件???????2240??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.log
?????文件?????198543??2016-11-17?15:35??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.obj
?????文件???49152000??2016-11-17?09:54??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.pch
?????文件??????70000??2016-11-17?11:16??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.res
?????文件???????5862??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\cl.command.1.tlog
?????文件?????103290??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\CL.read.1.tlog
?????文件???????4296??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\CL.write.1.tlog
?????文件???????5256??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\li
?????文件??????10042??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\li
?????文件???????1280??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\li
?????文件???????1114??2016-11-17?11:16??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\rc.command.1.tlog
?????文件???????3256??2016-11-17?11:16??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\rc.read.1.tlog
?????文件????????290??2016-11-17?11:16??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\rc.write.1.tlog
?????文件????????213??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSever.tlog\TCPSever.lastbuildstate
?????文件?????298812??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\TCPSeverDlg.obj
?????文件????3066880??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\vc120.idb
?????文件????9261056??2016-11-20?19:41??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\Debug\vc120.pdb
?????文件???????3880??2016-08-28?09:44??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\ReadMe.txt
?????文件??????67777??2013-07-22?01:18??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\res\TCPSever.ico
?????文件????????672??2016-08-28?09:44??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\res\TCPSever.rc2
?????文件???????1970??2016-08-28?10:08??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\resource.h
?????文件??????13014??2012-11-28?11:27??MFC_SOCKET與HTML5_WebSocket通信\TCPSever\TCPSever\sha1.cpp
............此處省略29個文件信息
- 上一篇:VC一個很簡單的屏保程序MFC
- 下一篇:grid+report5.6銳浪報表無水印
評論
共有 條評論