[Dev-C++] Internet programming again
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ben M. <ili...@at...> - 2007-12-07 03:05:28
|
hello. I am trying to write that winsock app that i was working on the
other day. I want to find the IP address of the computer that is
connecting to the server. Here is the code for the server application:
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
WSADATA wsadat;
SOCKET Socket, TempSocket = SOCKET_ERROR;
SOCKADDR_IN SockAddr;
SOCKADDR ConnAddr;
ifstream infile;
string filename = "C:\\counter.java";
char send_str[1], recv_str[6];
int a = 0, in_char, RetVal;
if (WSAStartup (MAKEWORD(1,1), &wsadat) != 0)
{
cout << "WSAStartup failed!!!";
}
Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Socket == INVALID_SOCKET)
{
cout << "Socket creation failed!!!";
}
SockAddr.sin_port = 50;
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.S_un.S_un_b.s_b1 = 192;
SockAddr.sin_addr.S_un.S_un_b.s_b2 = 168;
SockAddr.sin_addr.S_un.S_un_b.s_b3 = 1;
SockAddr.sin_addr.S_un.S_un_b.s_b4 = 102;
if (bind (Socket, (SOCKADDR *)(&SockAddr), sizeof (SockAddr)) ==
SOCKET_ERROR)
{
cout << "Attempt to bind failed!!!";
}
listen (Socket, 1);
while (TempSocket == SOCKET_ERROR)
{
TempSocket = accept (Socket, &ConnAddr, sizeof (ConnAddr));
}
Socket = TempSocket;
printf ("%s", ConnAddr.sa_data);
while (a <= filename.length())
{
send_str[0] = filename[a];
cout << send_str;
send (Socket, send_str, 1, 0);
++a;
}
infile.open (filename.c_str());
while (!infile.eof())
{
in_char = infile.get();
send_str[0] = in_char;
cout << send_str;
send (Socket, send_str, 1, 0);
}
infile.close();
while (RetVal == SOCKET_ERROR)
{
RetVal = recv (Socket, recv_str, 6, 0);
}
cout << recv_str;
system ("pause");
return 0;
}
The problem text is highlighted in green. I get the error message
"invalid conversion from 'unsigned int' to 'int *' initializing argument
3 of 'SOCKET accept (SOCKET, sockaddr*, int*)'. But how else am i
supposed to pass the size of the structure to the method?
|