Following is a C++ client(Network Programming) code, I need to translate it to TCL, if anybody can help me, I shall be thankfull ...
//<CLIENT.CPP>
#include <iostream>
#include <conio.h>
#include <string>
#include <winsock2.h>
#include <fstream>
using namespace std;
void main()
{
string ip = "127.0.0.1";
int port = 6789;
WSADATA wsadat;
WORD rVersion;
rVersion = MAKEWORD(2,0);
if(WSAStartup(rVersion, &wsadat) != NO_ERROR)
{
cout<<"WSA initialization failed.\n";
WSACleanup();
return;
}
SOCKET client;
client = socket(AF_INET, SOCK_STREAM, 0);
if(client == INVALID_SOCKET)
{
cout<<"Error creating socket.\n";
WSACleanup();
return;
}
SOCKADDR_IN server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(ip.c_str());
server.sin_port = htons(port);
if(connect(client, (SOCKADDR*) &server, sizeof(server)) == SOCKET_ERROR)
{
cout<<"Connection cannot be established. \n";
WSACleanup();
return;
}
//send and receive data
char* buf = "Hello TCP-IP World!\n";//new unsigned char[length];
send(client, buf, strlen(buf)+1, 0);
shutdown(client, SD_BOTH);
closesocket(client);
WSACleanup();
return;
}