Using Sockets to post to port
Hi, I'm trying to use a simple socket connection to drop a string to local port, so that another application that is constantly listening to that port can grab the string.
I used telnet to detetermine that I am opening the socket and the port is active, I can attach to the port, but when I use a send () to send my string to the port, I do not see any data come accross that port. I am a bit stumped, been searching and reading google stuff for days and had no success, can anyone point me to where I'm going wrong...
Code:
// Send converted line back to client.
WORD sockVersion;
WSADATA wsaData;
int rVal;
sockVersion = MAKEWORD(1,1);
//start dll
WSAStartup(sockVersion, &wsaData);
//create socket
SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_TCP);
if(s == INVALID_SOCKET)
{
AfxMessageBox("Failed socket()");
WSACleanup();
// return SERVER_SOCKET_ERROR;
}
//fill in sockaddr_in struct
SOCKADDR_IN sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(10001);
sin.sin_addr.s_addr = INADDR_ANY;
//bind the socket
rVal = bind(s, (LPSOCKADDR)&sin, sizeof(sin));
if(rVal == SOCKET_ERROR)
{
AfxMessageBox("Failed bind()");
WSACleanup();
// return SERVER_SOCKET_ERROR;
}
//get socket to listen
rVal = listen(s, 2);
if(rVal == SOCKET_ERROR)
{
AfxMessageBox("Failed listen()");
WSACleanup();
// return SERVER_SOCKET_ERROR;
}
//allow client connections
//wait for a client
SOCKET client;
client = accept(s, NULL, NULL);
Sleep (10000);
send(s,m_Barcode,strlen(m_Barcode),0);
Sleep (10000);
//closesocket() closes the socket and releases the socket descriptor
closesocket (client);
closesocket(s);
WSACleanup();