|
-
November 26th, 2008, 01:44 AM
#1
finding problem in recieving message via socket
Hi...
I am facing a problem in receiving a message from the server. Actually I am developing a server cleint code using WinAPIs(not MFC). My server is a property sheet which has a send button and a edit box . Same is there on the client. My client is a dialog box having an edit box and a recieve button. Now my problem is while if I write anything on the server'z edit box and click send I am able to send the message which I am checking by a message box and on the client side I am able to recieve also which is also checked by message box . But I am not able to produce the same message been recieved on the client's edit box. I have the client and the server code and I am not able to fine where exactly my problem lies.
On the server side I have
char szSendBuffer[1024] = GetDlgItemString(IDC_EDIT_SEND);// IDC_EDIT_SEND is the ID for the edit box.
if(send(ClientSocket,&szSendBuffer[0],sizeof(szSendBuffer),0)== -1)
MessageBox(NULL,TEXT("Message cant be send"),NULL,MB_ICONERROR);
else
MessageBox(NULL,TEXT("Message is succesfully send to the client"),NULL,MB_ICONERROR);
The GetDlgItemString function is
char GetDlgItemString(int nIDDlgItem)
{
int nLength = 1 + ::GetWindowTextLength(GetDlgItem(hModelssDialog, nIDDlgItem));
char String;
if (nLength > 0)
{
TCHAR* szString = new TCHAR[nLength];
if (NULL == szString)
MessageBox(NULL,TEXT("string is null"),NULL,MB_ICONERROR);
::GetDlgItemText(hModelssDialog, nIDDlgItem, szString, nLength);
String = (char)szString;
delete []szString;
}
return String;
}
Here I am recieving the message box of message being send
In the client side I have
ZeroMemory(szRecvBuffer,sizeof(szRecvBuffer));
if(recv(ClientSocket,&szRecvBuffer[0],sizeof(szRecvBuffer),0) == -1)
MessageBox(NULL,TEXT("Data is not recieved from the server!"),NULL,MB_ICONERROR);
else
MessageBox(NULL,TEXT("Data is recieved from the server!"),NULL,MB_ICONERROR);
Append(IDC_EDIT_RECEIVE, szRecvBuffer);
Here I recieve the messagebox comments as Data is recieved.
Now in the Append function I have
HWND hEdit = GetDlgItem(hModelssDialog1, nID);
EnableWindow(hEdit, TRUE);
int ndx = GetWindowTextLength (hEdit);
SendMessage (hEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
if(SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) buf)== -1)
MessageBox(NULL,TEXT("Message cant be shown"),NULL,MB_ICONERROR);
else
MessageBox(NULL,TEXT("Message is shown"),NULL,MB_ICONERROR);
This is the main function I am concerened with. Here I am not sure whether for printing the message on the edit box my approach is correct. But I am recieving the message box message as message is shown"
Please help me in soughting out this problem.
Thanks in advance!!!!!!!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|