|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
my strings get fuxxored when sent over tcp/ip
im making this chess game, and part of the data sent in the packet is a string with a message. here is the struct i use to send it:
Code:
struct Message //structure that contains data sent in the messages
{
char type; //type of message; { C - connect , D - disconnect
// , M - move , T - talk , S - status}
int row; //row #
int col; //column #
int oldRow; ///aha, found out we need to send the old position as well
int oldCol; // see above __/^
string talk; //good ol fashion **** talking between players, oh yea and comp messages
char piece; //the piece being moved
bool firstPlayer;//tells the player who is black and who is white, by default teh first
}; //one to register gets to be white... or is it black? ;0
all the data arrives fine besides the string; it arrives with odd symbols and mixed up characters. i have also tried using char * , CStrings, but they all get mixed up. when i try to use a char [] , then i get compile errors. anyone got any ideas on this? |
|
#2
|
||||
|
||||
|
You're going to have to decide how long your strings will get beforehand (and they cannot get any longer than this ever!), and you'll have to use a character array, eg
char str[255]; Anything else will just transmit pointers to locations in memory on the other machine over your socket |
|
#3
|
||||
|
||||
|
Back in mid April (c. 12 Apr), there was a discussion about passing dynamically allocated data (eg, a char* field in a struct) entitled, "Passing a dynamic array across a network" at http://forums.devshed.com/t58349/s.html .
This is the first time I've tried to include a link to another thread. Hope it works. |
|
#4
|
||||
|
||||
|
yep that looks like the answer. i'll try that out when i get home.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > my strings get fuxxored when sent over tcp/ip |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|