About Store Forum Documentation Contact
Donations:
140$/mo



Post Reply 
Sending structure over Socket
Author Message
Nesariel Offline
Member

Post: #1
Sending structure over Socket
Hello I have the following problem
I try to connect a client with a server using the Socket class. The server receives data but something wrong or <bad Ptr>. When the server responses Int Invalid_Password The client receives the right data.

CODE:

struct ServerLogin
{
Str sUserName;
Str sServerPassword;
};

SERVER:
INIT:
Int iPort = Convert::ToInt(options.sPort);
socket.createUdp();
socket.bind(SockAddr().setServer(iPort));
socket.block(false);
UPDATE:
for(SockAddr addr;wink
{
ServerLogin loginRequest;
Int rcv=socket.receive(addr,&loginRequest,SIZE(loginRequest));
if( rcv<0)break;
Client *c=NULL;
REPA(clients)if(clients[i].address==addr){c=&clients[i]; break;} // check if it's already stored on the list
if(!c) // if not found in add it
login(&addr, &loginRequest, c);
}

CLIENT:
ServerLogin loginRequest;

loginRequest.sServerPassword = sServerPassword;
loginRequest.sUserName = sUserName;

Int iPort = Convert::ToInt(sServerPort);
serverAddress.ip(sServerIp);
serverAddress.port(iPort);
Int iConnectionState = CONN_INVALID;

socket.createUdp();
socket.connect(serverAddress);
socket.block(false);

socket.send(serverAddress,&loginRequest,SIZE(loginRequest));

greetings Nes
01-17-2011 10:35 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Sending structure over Socket
hi,

you can't send Str object (it has pointers to memory), you should either save it to file in memory File::putStr, or use Char text[20];
01-17-2011 03:00 PM
Find all posts by this user Quote this message in a reply
Post Reply