0번문제 ;; 처음에 조낸 삽질; 접속했는데 아무것도 안나오고;
문제가 먼지도 몰랐다;
요점은 결국 코딩;
처음에 4개 숫자라길래 포트인줄알고 조낸 더해서 보냈다;; 하지만 서버는 알수없는문자만 계속 토하고;;
접속해서 숫자를 주는건가 했는데 역시 이상한 문자만 조낸 토하고;
뭐 결국 했지만 처음에 접속하면 어떤 값을준다; 이거 다 더해서 다시 보내면 답이~ 짜짠~
코딩을 잘 못해서 소스는 지랄;;;
환경 : windows vista / VS2008 환경
하시려면 ws2_32.lib추가해주셔야 합니다.
추가법은 제 블로그 팁에 보시면 나와있어요.
/* stdafx.h */
#include <stdio.h>
#include <tchar.h>
#include <winsock.h> /* for socket(),... */
#include <stdlib.h> /* for exit() */
#include <direct.h>
#include <conio.h>
#include "stdafx.h"
#define RCVBUFSIZE 64
union ChangeU
{
char hex[4];
unsigned int sum;
};
void main(int argc, char *argv[])
{
union ChangeU con1,con2,con3,con4,sum;
int sock;
struct sockaddr_in echoServAddr;
unsigned short echoServPort;
char *servIP;
char *echoString;
char echoBuffer[RCVBUFSIZE];
int echoStringLen;
int bytesRcvd, totalBytesRcvd;
WSADATA wsaData;
servIP = "69.55.233.89";
echoServPort = 5842;
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)
{
fprintf(stderr, "WSAStartup() failed");
exit(1);
}
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
printf("error socket\n");
memset(&echoServAddr, 0, sizeof(echoServAddr));
echoServAddr.sin_family = AF_INET;
echoServAddr.sin_addr.s_addr = inet_addr(servIP);
echoServAddr.sin_port = htons(echoServPort);
if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
printf("error connect\n");
printf("connected!\n");
totalBytesRcvd = 0;
printf("Received: ");
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0)
printf("error recv\n");
totalBytesRcvd += bytesRcvd;
echoBuffer[bytesRcvd] = '\0';
unsigned int bufferx=unsigned int(echoBuffer);
printf("receved!\n");
printf(echoBuffer);
printf("\n%u\n",bufferx);
echoStringLen=strlen(echoBuffer);
printf("LEN = %d\n",echoStringLen);
con1.hex[0]=echoBuffer[0];
con1.hex[1]=echoBuffer[1];
con1.hex[2]=echoBuffer[2];
con1.hex[3]=echoBuffer[3];
memset(echoBuffer,0,RCVBUFSIZE);
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0)
printf("error recv\n");
totalBytesRcvd += bytesRcvd;
con2.hex[0]=echoBuffer[0];
con2.hex[1]=echoBuffer[1];
con2.hex[2]=echoBuffer[2];
con2.hex[3]=echoBuffer[3];
con3.hex[0]=echoBuffer[4];
con3.hex[1]=echoBuffer[5];
con3.hex[2]=echoBuffer[6];
con3.hex[3]=echoBuffer[7];
con4.hex[0]=echoBuffer[8];
con4.hex[1]=echoBuffer[9];
con4.hex[2]=echoBuffer[10];
con4.hex[3]=echoBuffer[11];
printf("%u %u %u %u",con1.sum,con2.sum,con3.sum,con4.sum);
sum.sum=con1.sum+con2.sum+con3.sum+con4.sum;
printf("\nSUM = %u\n",sum.sum);
printf("%x ",(unsigned char)sum.hex[0]);
printf("%x ",(unsigned char)sum.hex[1]);
printf("%x ",(unsigned char)sum.hex[2]);
printf("%x\n",(unsigned char)sum.hex[3]);
memset(echoBuffer,0,RCVBUFSIZE);
echoBuffer[0]=(unsigned char)sum.hex[0];
echoBuffer[1]=(unsigned char)sum.hex[1];
echoBuffer[2]=(unsigned char)sum.hex[2];
echoBuffer[3]=(unsigned char)sum.hex[3];
echoStringLen = strlen(echoBuffer);
printf("SEND MSG = %s %d\n",echoBuffer,echoBuffer);
printf("LEN = %d\n",echoStringLen);
if (send(sock, echoBuffer, echoStringLen, 0) != echoStringLen)
printf("error send\n");
printf("sended!\n");
memset(echoBuffer,0,RCVBUFSIZE);
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0)
printf("error recv\n");
totalBytesRcvd += bytesRcvd;
echoBuffer[bytesRcvd] = '\0';
printf("\n");
printf("%s %x %d",echoBuffer,echoBuffer,echoBuffer);
printf("\n");
closesocket(sock);
WSACleanup();
getch();
exit(0);
}
C:\Users\nvdark\Documents\Visual Studio 2008\Projects\vortex_0\Debug>vortex_0.ex
e
connected!
Received: receved!
??
2225832
LEN = 4
764362167 745031041 704972364 738382526
SUM = 2952748098
42 5c ff af
SEND MSG = B\? 2225832
LEN = 4
sended!
Username: vortex1 Password: XXXXXXXXX 21f6a8 2225832