#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    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. #2
  3. unix hermit
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    http://www.rfc791.org
    Posts
    18
    Rep Power
    0
    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
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,253
    Rep Power
    2222
    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.
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    yep that looks like the answer. i'll try that out when i get home.

IMN logo majestic logo threadwatch logo seochat tools logo