![]() |
| | #1 |
| C++ Enthusiast Join Date: Mar 2005 Location: MI
Posts: 532
| recv() typecasting error Code: case FD_READ:
recv((SOCKET)wParam,(struct JCPPM *)&JCPPpacket,sizeof(struct
JCPPM),0);
if(strcmp(JCPPpacket.data,"")!=0)
ConsoleMessage("",JCPPpacket.data,false);
break;
Code: struct JCPPM
{
unsigned int type;
char *sender;
char *data;
};
struct JCPPM JCPPpacket;
Code: 132 C:\WINDOWS\Desktop\JCPPChat\main.cpp cannot convert `JCPPM*' to `char*' for argument `2' to `int recv(SOCKET, char*, int, int)'
__________________ Trinity: "Neo... nobody has ever done this before." Neo: "That's why it's going to work." c9915ec6c1f3b876ddf38514adbb94f0 |
| jmd15 is offline | |
| | #2 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,020
| The recv() function takes a buffer of type char*, so that is what you need to cast to. Code: recv((SOCKET)wParam,(char*)&JCPPpacket,sizeof(struct |
| bithub is offline | |
| | #3 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,020
| Also keep in mind that the structure you are sending has two pointer values in it, and those pointer values will be invalid once you send them out a socket. |
| bithub is offline | |
| | #4 |
| Registered User Join Date: Jan 2005
Posts: 847
| Aso keep in mind that recv might not get the entire structure in a single call. The return value will tell you how many bytes were recieved. |
| Quantum1024 is offline | |
| | #5 |
| C++ Enthusiast Join Date: Mar 2005 Location: MI
Posts: 532
| @ bithub So you're saying it won't send the entire structure? As in, after I receive the structure, it won't have the JCPPpacket.type and JCPPpacket.sender? So it's basically just sending the data segment? I probably have misunderstood you and I apologize. Thank you both for your quick replies.
__________________ Trinity: "Neo... nobody has ever done this before." Neo: "That's why it's going to work." c9915ec6c1f3b876ddf38514adbb94f0 |
| jmd15 is offline | |
| | #6 |
| Registered User Join Date: Jan 2005
Posts: 847
| What bithub is saying is that the structure will be sent but not the data pointed to by sender and data. Only the pointers themselves will actually be sent and who knows what these will actually point to on another machine. To send these things you would need to pass the sender and data pointers to send. |
| Quantum1024 is offline | |
| | #7 |
| C++ Enthusiast Join Date: Mar 2005 Location: MI
Posts: 532
| Hmm, alrighty then. It looks as if the purpose I created that struct is defeated because it won't send all the data associated with it. I might as well just send segment by segment(for example send the sender name first, then the type and then the message) instead of a struct, UNLESS I'm missing something. What is the positive side of sending structs against sending the data in segments? Thanks for clearing that up Quantum.
__________________ Trinity: "Neo... nobody has ever done this before." Neo: "That's why it's going to work." c9915ec6c1f3b876ddf38514adbb94f0 |
| jmd15 is offline | |
| | #8 |
| Registered User Join Date: Jan 2005
Posts: 847
| Unless you're using some kind of deliminater at the end of each messages to show it's end you should send the length before so that the recieving end knows how much to recieve. Use structs when it is a fixed amount of fixed sized items, use a buffer when it is a variable amount. If the data you're sending is mostly text then I would sugest using a deliminater like \r\n and using another deliminater to seperate message sender and message data. For example Code: Type::Message Sender::Message Data\r\n |
| Quantum1024 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting an error with OpenGL: collect2: ld returned 1 exit status | Lorgon Jortle | C++ Programming | 6 | 05-08-2009 08:18 PM |
| An error is driving me nuts! | ulillillia | C Programming | 5 | 04-04-2009 09:15 PM |
| Making C DLL using MSVC++ 2005 | chico1st | C Programming | 26 | 05-28-2008 01:17 PM |
| Learning OpenGL | HQSneaker | C++ Programming | 7 | 08-06-2004 08:57 AM |
| Couple C questions :) | Divx | C Programming | 5 | 01-28-2003 01:10 AM |