Click here to Skip to main content
16,007,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCComBSTR and _bstr_t Pin
microsoftcertificate28-Apr-05 22:59
sussmicrosoftcertificate28-Apr-05 22:59 
GeneralRe: CComBSTR and _bstr_t Pin
Michael Dunn29-Apr-05 6:46
sitebuilderMichael Dunn29-Apr-05 6:46 
GeneralRe: CComBSTR and _bstr_t Pin
microsoftcertificate29-Apr-05 12:44
sussmicrosoftcertificate29-Apr-05 12:44 
GeneralRe: CComBSTR and _bstr_t Pin
ThatsAlok3-May-05 0:33
ThatsAlok3-May-05 0:33 
GeneralInvalidating problem in win32 Pin
ledallam28-Apr-05 22:41
ledallam28-Apr-05 22:41 
GeneralRe: Invalidating problem in win32 Pin
Blake Miller29-Apr-05 4:09
Blake Miller29-Apr-05 4:09 
GeneralBitmap Pin
Rassul Yunussov28-Apr-05 21:44
Rassul Yunussov28-Apr-05 21:44 
GeneralWSA Error 10038 - Veeery strange... Pin
DKT_28-Apr-05 21:28
DKT_28-Apr-05 21:28 
Hi,

I have coded a chat app. Server-Client based.

Everything worked fine. And suddenly I cant send a normal message anymore, which worked before.

What it does:

The client connects to the server and sends its name, which works. I get all contacts, and see them in my buddylist.
But if I want to send a message to one of the users (which goes to the server first), I get the above mentioned error.
This one means, that I am trying to send the message with a socket, which is no socket?!
But the socket is ok, it has a number, I mean, I get contacts through it etc.
I declared it globally cause I need it very often.
The message I want to send is ok, the string length is ok.

Whats wrong there?

I am coding in VC++6 without MFC.

here my little codesnippets:

/*** Creating socket ***/
if(WSAStartup(MAKEWORD(1,1), &wsaData) != NULL)
return(error(hDlg, "Cant initialize Winsock!"));

if((sock_clnt = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET)
return(error(hDlg, "Cant create local socket!"));

if((phostent = gethostbyname(ip)) == NULL)
return error(hDlg, "Cant get host by name!");

memcpy((char FAR *)&(sockin_clnt.sin_addr), phostent->h_addr, phostent->h_length);
sockin_clnt.sin_family = AF_INET;
sockin_clnt.sin_port = htons(port);

if(connect(sock_clnt, (SOCKADDR *)&sockin_clnt, sizeof(sockin_clnt)) == SOCKET_ERROR)
return error(hDlg, "Cant connect!");

/*** Here the problem call: ***/
int test = 0;
int test2 = 0;
test2 = strlen(msg2srvr);
if((test = send(sock_clnt, msg2srvr, test2, 0)) <= 0)
{
test = WSAGetLastError();
error(hDlg, "Cant send message!");
}

/*** Socket declaration before main function (globally): ***/

SOCKET sock_clnt;



Thats it. I really hope you can help me. Such errors are so annoying...

EDIT: What I just saw: The value of the socket from the client, changes between sending name at the beginning and sending a message when pressing the send button. Is that normal?
I Just connected to the destination socket, and run a thread with an endless loop receiving data with recv(). And if user presses the send button, it sends data through the same socket with send(). This is how it should work, right?


DKT
GeneralRe: WSA Error 10038 - Veeery strange... Pin
Alexander M.,29-Apr-05 9:10
Alexander M.,29-Apr-05 9:10 
GeneralRe: WSA Error 10038 - Veeery strange... Pin
DKT_1-May-05 1:08
DKT_1-May-05 1:08 
GeneralDriver Project in Visual C++ Pin
Anonymous28-Apr-05 21:18
Anonymous28-Apr-05 21:18 
GeneralRe: Driver Project in Visual C++ Pin
ThatsAlok28-Apr-05 21:25
ThatsAlok28-Apr-05 21:25 
GeneralRe: Driver Project in Visual C++ Pin
Alexander M.,29-Apr-05 9:06
Alexander M.,29-Apr-05 9:06 
Generalavi from sequence jpeg files Pin
hausen28-Apr-05 21:09
hausen28-Apr-05 21:09 
GeneralRe: avi from sequence jpeg files Pin
ThatsAlok28-Apr-05 21:17
ThatsAlok28-Apr-05 21:17 
GeneralRe: avi from sequence jpeg files Pin
Ted Ferenc28-Apr-05 21:33
Ted Ferenc28-Apr-05 21:33 
GeneralHelp with 2d-array multiplication Pin
aaadetos28-Apr-05 21:04
aaadetos28-Apr-05 21:04 
GeneralLSB Insertion Algorithm Pin
VPNampoothiri28-Apr-05 20:50
VPNampoothiri28-Apr-05 20:50 
GeneralRe: LSB Insertion Algorithm Pin
Alexander M.,29-Apr-05 9:07
Alexander M.,29-Apr-05 9:07 
QuestionHow to Convert BITMAP image to IplImage Format Pin
hprasain28-Apr-05 20:12
hprasain28-Apr-05 20:12 
Generalcontrolling web cam Pin
Randil28-Apr-05 20:12
Randil28-Apr-05 20:12 
GeneralRe: controlling web cam Pin
ThatsAlok28-Apr-05 20:23
ThatsAlok28-Apr-05 20:23 
GeneralThreads Pin
pr_mk28-Apr-05 20:08
pr_mk28-Apr-05 20:08 
GeneralRe: Threads Pin
Ryan Binns28-Apr-05 20:48
Ryan Binns28-Apr-05 20:48 
GeneralUsing DMA to transfer data between two memory locations Pin
Vitaly Kashkarov28-Apr-05 20:07
Vitaly Kashkarov28-Apr-05 20:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.