Hejsa jeg har denne kode:
#include <iostream>
#include <winsock2.h>
#include <mysql/mysql.h>
using namespace std;
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state, n;
int main() {
cout << "test test \r\n";
cout << "Newest version ";
mysql_init(&mysql);
connection = mysql_real_connect(&mysql,"localhost","root","","test",0,0,0);
if (connection == NULL) {
cout << mysql_error(&mysql) << endl;
return 0;
}
query_state = mysql_query(connection, "select * FROM version");
if (query_state !=0) {
cout << mysql_error(connection) << endl;
return 0;
}
result = mysql_store_result(connection);
while ( ( row = mysql_fetch_row(result)) != NULL ) {
cout << row[1] << "\r\n";
}
cout << "Checking for updates...\r\n";
cout << "::: Ready for connections! :::\r\n";
SOCKET server;
WSADATA wsaData;
sockaddr_in local;
int wsaret=WSAStartup(0x101,&wsaData);
SOCKET client;
sockaddr_in from;
int fromlen=sizeof(from);
if(wsaret!=0)
{
return 0;
}
local.sin_family=AF_INET;
local.sin_addr.s_addr=INADDR_ANY;
local.sin_port=htons((u_short)6666);
server=socket(AF_INET,SOCK_STREAM,0);
if(server==INVALID_SOCKET)
{
return 0;
}
if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
{
return 0;
}
if(listen(server,10)!=0)
{
return 0;
}
while(true)
{
char temp[512];
client=accept(server,(struct sockaddr*)&from,&fromlen);
sprintf(temp, "OK");
int ret;
char buffer[1024];
memset(buffer, 0, sizeof (buffer));
ret = recv(client, buffer, sizeof(buffer), 0);
send(client,temp,strlen(temp),0);
cout << "Connection from " << inet_ntoa(from.sin_addr) << "\r\n";
cout << "Requested data id: " << ret << "\r\n";
closesocket(client);
}
closesocket(server);
mysql_close(connection);
WSACleanup();
return 0;
}
Nede ved " cout << "Requested data id: " << ret << "\r\n";"
Når jeg så sender en besked til min socket TCP server, f.eks. jeg sender "123". Når det så kommer frem bliver det bare til 3, ikke 123. Hvordan kan jeg få den til at skrive mig værdien i stedet for længden på værdien?
Indlæg senest redigeret d. 09.04.2010 11:47 af Bruger #15047