   connecting to software via sockets
  Hey guysUsing c++ DirectX9:I have network code to connect to a web address which seems to work, but is untested. What i want is code to connect to another program on the same machine so strings can be sent. I have been told i need to create a port to use which they can connect through. I don't know how to do this. My existing network code is shown below.WORD sockVersion;WSADATA wsaData;//int nret; made global   sockVersion = MAKEWORD(1, 1);   // Initialize Winsock as beforeWSAStartup(sockVersion, &wsaData);   // Store information about the serverLPHOSTENT hostEntry;   hostEntry = gethostbyname("www.hal-pc.org");// Specifying the server by its name;// another option is gethostbyaddr()if (!hostEntry) {nret = WSAGetLastError();//ReportError(nret, "gethostbyname()");    // Report the error as before WSACleanup();return NETWORK_ERROR;}   // Create the socket//SOCKET theSocket; // made global   theSocket = socket(AF_INET,  // Go over TCP/IPSOCK_STREAM,   // This is a stream-oriented socketIPPROTO_TCP);  // Use TCP rather than UDPif (theSocket == INVALID_SOCKET) {nret = WSAGetLastError();//ReportError(nret, "socket()"); WSACleanup();return NETWORK_ERROR;}// Fill a SOCKADDR_IN struct with address informationSOCKADDR_IN serverInfo;   serverInfo.sin_family = AF_INET;serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);   // See the explanation in the tutorialserverInfo.sin_port = htons(80);  // Change to network-byte order and// insert into port field// Connect to the servernret = connect(theSocket,(LPSOCKADDR)&serverInfo,sizeof(struct sockaddr));   if (nret == SOCKET_ERROR) {nret = WSAGetLastError();//ReportError(nret, "connect()"); WSACleanup();return NETWORK_ERROR;}// SUCCESSFULLY CONNECTED!Can this be relatively easily altered to connect to a local host and to create a port.Thank youStuart   
  Yes, you just need to connect to "localhost". Although you'd be better to change to to this:WORD sockVersion;WSADATA wsaData;//int nret; made global   sockVersion = MAKEWORD(1, 1);   // Initialize Winsock as beforeWSAStartup(sockVersion, &wsaData);// Create the socket//SOCKET theSocket; // made global   theSocket = socket(AF_INET,  // Go over TCP/IPSOCK_STREAM,   // This is a stream-oriented socketIPPROTO_TCP);  // Use TCP rather than UDPif (theSocket == INVALID_SOCKET) {nret = WSAGetLastError();//ReportError(nret, "socket()"); WSACleanup();return NETWORK_ERROR;}// Fill a SOCKADDR_IN struct with address informationSOCKADDR_IN serverInfo;   serverInfo.sin_family = AF_INET;serverInfo.sin_addr = inet_addr("127.0.0.1");serverInfo.sin_port = htons(80);  // Change to network-byte order and// insert into port field// Connect to the servernret = connect(theSocket,(LPSOCKADDR)&serverInfo,sizeof(struct sockaddr));   if (nret == SOCKET_ERROR) {nret = WSAGetLastError();//ReportError(nret, "connect()"); WSACleanup();return NETWORK_ERROR;}// SUCCESSFULLY CONNECTED!So you don't have to lookup the hostname. Also, what you have is only half the code - that's the client-side code. You also need more to call bind() and accept() to accept the connection on the other end.   ;  Cheers steve thats sounds easy enough. I am getting one error tho with the line: serverInfo.sin_addr = inet_addr("127.0.0.1");The error is: error C2679: binary '=' : no operator found which takes a right-hand operand of type 'unsigned long' (or there is no acceptable conversion)I don't know if im being stupid but I don't know why it is wrong?cheersstuart   ;  hi istewypeza.Use serverInfo.sin_addr.s_addr = inet_addr("127.0.0.1");sin_addr is a struct containing a union, so to access the long member use s_addr.   