Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #pragma comment(lib, "ws2_32.lib")
- using namespace std;
- int main()
- {
- // Startup
- WSADATA wdata;
- int iStart = WSAStartup(MAKEWORD(2,2), &wdata);
- if( iStart == SOCKET_ERROR )
- {
- cout << "Startup Fail" << endl;
- }
- else {
- cout << "Startup Success" << endl;
- }
- // Socket
- SOCKET sConnect = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if( sConnect == SOCKET_ERROR )
- {
- cout << "Socket Fail" << endl;
- WSACleanup();
- }
- else {
- cout << "Socket Success" << endl;
- }
- // Info
- SOCKADDR_IN info;
- info.sin_family = AF_INET;
- info.sin_addr.s_addr = inet_addr("127.0.0.1");
- info.sin_port = htons(22580);
- // Connect
- int iConn = connect(sConnect, (SOCKADDR *)&info, sizeof(info));
- if( iConn == SOCKET_ERROR )
- {
- cout << "Connect Fail" << endl;
- WSACleanup();
- closesocket(sConnect);
- }
- else {
- cout << "Connect Success" << endl;
- }
- // Recieve
- char cRecv[8192];
- int iRecieve;
- while(true)
- {
- iRecieve = recv(sConnect, cRecv, sizeof(cRecv), 0);
- for(int i = 0; i < iReceive; i++) printf("%.2X", cRecv[i]);
- printf("\n\n");
- }
- if( iRecieve == SOCKET_ERROR )
- {
- cout << "Recieve Fail" << endl;
- }
- else {
- cout << cRecv << endl;
- }
- WSACleanup();
- closesocket(sConnect);
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment