S
Syed Babu
Guest
Correct me if Im wrong. The socket server and client does not dependent any development languages. Irrespective of the language, they should work fine.
Here is my issue:
My server is being developed using TCL ( Tool Command Language ) and here is the following command to create server:
#Callback function called when the client connected to server
proc ServerOpenCallBack {channel addr port} {
tk_messageBox -message "Client Connected"
}
#Create a socket server
set var [socket -server ServerOpenCallBack 20000]
My Client is developed using C++ and using native OS calls to connect to the socket:
// Socket_Client.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <Winsock2.h>
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
int iResult = -1;
char szPath[128] = "";
WSADATA wsaData;
//Intialize the win socket dll by passing highest version of windows socket specification
WSAStartup(MAKEWORD(2, 2), &wsaData);
//Get the host name
gethostname(szPath, sizeof(szPath));
//Get the host by name and fetch the id address
hostent* pHostEnt = gethostbyname(szPath);
in_addr* pInAddress = (in_addr*)(*pHostEnt->h_addr_list);
char* szIPAddresss = inet_ntoa(*pInAddress);
//Create an unnamed socket for the server
int client_socket_fd = socket(AF_INET,SOCK_STREAM,0 );
//Connect the client to the port
sockaddr_in client_address;
client_address.sin_family = AF_INET;
client_address.sin_addr = *pInAddress;
client_address.sin_port = 20000;
int client_addr_len = sizeof(sockaddr_in);
iResult = connect(client_socket_fd, (struct sockaddr *)&client_address, client_addr_len);
if( iResult != 0 )
{
int iErrCode = WSAGetLastError();
cout<<iErrCode<<endl;
}
char ch = X;
DWORD nbBytesWritten = 0;
int ierr = send( client_socket_fd,&ch,1,0 );
WSACleanup();
return 0;
}
When I ran the above code, the "connect" call fails and returns the error code 10061 ( WSAECONNREFUSED ).
Findings:
set sockVar [socket -async 19.76.34.159 20000]
Where 19.76.34.159 is the IP address of my system.
Could not find out what is wrong. Your help is appreciated.
Continue reading...
Here is my issue:
My server is being developed using TCL ( Tool Command Language ) and here is the following command to create server:
#Callback function called when the client connected to server
proc ServerOpenCallBack {channel addr port} {
tk_messageBox -message "Client Connected"
}
#Create a socket server
set var [socket -server ServerOpenCallBack 20000]
My Client is developed using C++ and using native OS calls to connect to the socket:
// Socket_Client.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <Winsock2.h>
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
int iResult = -1;
char szPath[128] = "";
WSADATA wsaData;
//Intialize the win socket dll by passing highest version of windows socket specification
WSAStartup(MAKEWORD(2, 2), &wsaData);
//Get the host name
gethostname(szPath, sizeof(szPath));
//Get the host by name and fetch the id address
hostent* pHostEnt = gethostbyname(szPath);
in_addr* pInAddress = (in_addr*)(*pHostEnt->h_addr_list);
char* szIPAddresss = inet_ntoa(*pInAddress);
//Create an unnamed socket for the server
int client_socket_fd = socket(AF_INET,SOCK_STREAM,0 );
//Connect the client to the port
sockaddr_in client_address;
client_address.sin_family = AF_INET;
client_address.sin_addr = *pInAddress;
client_address.sin_port = 20000;
int client_addr_len = sizeof(sockaddr_in);
iResult = connect(client_socket_fd, (struct sockaddr *)&client_address, client_addr_len);
if( iResult != 0 )
{
int iErrCode = WSAGetLastError();
cout<<iErrCode<<endl;
}
char ch = X;
DWORD nbBytesWritten = 0;
int ierr = send( client_socket_fd,&ch,1,0 );
WSACleanup();
return 0;
}
When I ran the above code, the "connect" call fails and returns the error code 10061 ( WSAECONNREFUSED ).
Findings:
- But when I tried to connect the above TCL server with a client written in TCL it connects fine and shows the message box "Client connected". Below is my TCL client code:
set sockVar [socket -async 19.76.34.159 20000]
Where 19.76.34.159 is the IP address of my system.
- Similarly for my C++ client code shown above, if I write server in C++ and it works fine.
Could not find out what is wrong. Your help is appreciated.
Continue reading...