[Windows Mobile Development and Hacking General] kireol:
I'm developing a client PPC app on my Tilt that connects to a pre-existing server that runs on other applications just fine. So I'm sure the server is fine. I'm just doing something wrong in my client. I've tested the server with telnet and it works flawlessly too.

what should happen is:

1)Client connects.

2)Client sends a "password\r\n"

3)Server responds with "Authenticated ok"

4)Client sends "/status\r\n"

5)Server responds with

"Version: 1.5.7

Attached: False

Mode: None

Profile: C:\Profiles\afile.txt

Log: None

---"

If I do steps 1-3, my code works flawlessly. When I try to step 4-5 it doesnt work. actually step 4 doesnt hang at all. But when my client tries to recv step 5, it hangs. horribly.

What am I doing wrong in my 2nd send and receive that I'm not doing in my first?

int ConnectToServer(HWND hWnd)
{
// Declare and initialize variables.
int iResult;
WSADATA wsaData;
static char returnText[512];
SOCKET ConnectSocket;
struct sockaddr_in clientService;

int recvbuflen = DEFAULT_BUFLEN;
char recvbuf[DEFAULT_BUFLEN] = "";

// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR) { sprintf(returnText,"WSAStartup failed with error: %d\n", iResult);	return(1); }

// Create a SOCKET for connecting to server
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ConnectSocket == INVALID_SOCKET) { sprintf(returnText,"socket failed with error: %ld\n", WSAGetLastError()); WSACleanup();return(2); }
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "24.2.2.2" );
clientService.sin_port = htons( 3200 );

//MYSTEP 1
// Connect to server.
iResult = connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
if (iResult == SOCKET_ERROR) {sprintf(returnText,"connect failed with error: %d\n", WSAGetLastError() ); closesocket(ConnectSocket);WSACleanup();return(3); }

char outtext[50];
//MYSTEP 2
// Send password
strcpy (outtext,"mypassword\r\n");
iResult = send( ConnectSocket, outtext, (int)strlen(outtext)+1, 0 );
if (iResult == SOCKET_ERROR)
{ sprintf(returnText,"send() failed with error: %d\n", WSAGetLastError());closesocket(ConnectSocket);WSACleanup();return(4);
}

//MYSTEP 3
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
{
}
else if ( iResult == 0 )
{ strcpy(recvbuf, "connection was closed");}
else
{ sprintf(recvbuf,"recv failed: %d\n", WSAGetLastError()); }
mbstowcs(STATUS,recvbuf,strlen(recvbuf));

//MYSTEP 4
//send get status
strcpy (outtext,"/status\r\n");
iResult = send( ConnectSocket, outtext, (int)strlen(outtext)+1, 0 );
if (iResult == SOCKET_ERROR)
{
sprintf(returnText,"send() failed with error: %d\n", WSAGetLastError());closesocket(ConnectSocket);WSACleanup();return(4);
}

//MYSTEP 5
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
{
}
else if ( iResult == 0 )
{ strcpy(recvbuf, "connection was closed");}
else
{ sprintf(recvbuf,"recv failed: %d\n", WSAGetLastError()); }
mbstowcs(STATUS,recvbuf,strlen(recvbuf));

// shutdown the connection since no more data will be sent
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
sprintf(returnText,"shutdown failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return(5);
}

// cleanup
closesocket(ConnectSocket);
WSACleanup();
return(6);
}

with telnet here's my output.

Authenticated ok
Version: 1.5.7
Attached: False
Mode: None
Profile: C:\Profiles\afile.txt
Log: None
---

thanks xda!