Re: Client/Server followup
Re: Client/Server followup
- Subject: Re: Client/Server followup
- From: email@hidden
- Date: Tue, 16 Oct 2001 05:46:17 -0400
On Tuesday, October 16, 2001, at 05:45 AM, email@hidden wrote:
Create a buffer that you are going to send, fill it out with
information (you know what bytes mean what)
and then send it. You can even use a struct that you cast into the
send()
kinda like:
#DEFINE MSG_INIT 0x01
#DEFINE MSG_CMD 0x02
#DEFINE COMMAND_REQUEST a 0x7
typedef stuct PROTMSG{
unsigned char msg_type;
unsigned char command;
//other things
//**
//**
}prot_msg;
int build_my_msg()
{
int ret_val;
//find out what type you need to build
prot_msg.msg_type = MSG_CMD;
prot_msg.command = COMMAND_REQUEST;
//i don't remember exactly the cast here, something like this though
ret_val = send(socket,(char*)prot_msg,msg_size);
if(!(ret_val >0)) //something is wrong
{
//handle the error, maybe reconnect
return E_SEND;
}
return 0;
}
on the other side, the server recieves:
maybe you are using FD_SET etc... (again i would have to look at the
params..
// check who is ready call FD_SET everytime
FD_SET(client_socket,FDS);
nReady = select(nX,&FDS,NULL,NULL);
if(!(nReady > 0))
{
//no work
//fall through if you are looping (in a thread like)
continue;
}
ret_val = recv(client_socket,(char*)prot_msg,msg_size);
//check ret_val make sure you got the right size etc...
switch (prot_msg.msg_type)
{
case MSG_INIT:
{
//new client, do what you have to do
break;
}
case MSG_CMD:
{
switch(prot_msg.command)
{
//handle the command types
case COMMAND_REQ:
handle_command_req(&response_msg_buf);
//...etc
}
On Tuesday, October 16, 2001, at 01:20 AM, Sam Goldman wrote:
OK, now that I have done a little research, I have formulated a new
question. How do I create my own protocol for chatting. I don't want
to use
a predefined one, but would rather make my own like Adam Hinkley's
Hotline
(although not for the same purpose).
Is that the correct question even?
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev