Originally Posted by
purpleturtle_97
Sorry I haven't been very clear here.
EDIT:
I have already created the socket in the main method, which basically results in:
Code:
int connection_sckt;
connection_sckt = accept(list_s, NULL, NULL);
//and then what I think should be...
echoFile(connection_sckt, filename)
//which would cop the contents of filename to the connection_sckt(if this is in fact the correct fd)
You should post your whole code and let us look at it.
Trust me... simply calling accept does not open a socket.
And using fput() to echo characters to the socket handle does not send data.
Here's an example of what it takes to open a listening socket in Winsock...
Code:
// initialize Client port/return port number
WORD InitNetwork(WORD Port)
{ WSADATA wsadata; // winsock startup
TCHAR hn[MAX_HOSTNAME]; // host name
DWORD hs = MAX_HOSTNAME; // host name size
SOCKADDR la; // local address
WORD lp = Port; // local port
// Load the Winsock DLL
if (WSAStartup(MAKEWORD(2,0),&wsadata))
return 0;
// initialize local socket
hSocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
if (hSocket == INVALID_SOCKET)
return 0;
// initialize localhost IP
GetComputerName(hn,&hs);
if (!GetHostAddr(hn,Port,&la))
return 0;
// bind on user designated Port
if (bind(hSocket,&la,sizeof(SOCKADDR)))
return 0;
// start rx thread
rxThread = CreateThread(NULL,0,&ReceiveDatagrams,NULL,0,0);
return lp; }
This is for UDP connections, TCP is a little different but no less complex.