Hey guys,
I've been working on a fairly simple chat app. The GUI and everything looks great, and works well, but this networking stuff is driving me nuts. It seems like it should be pretty simple, but I can't get it to work.
I found a chat example from Michael Schwarz which is written in C-script. I adapted it to Lite-C, but it doesn't work. It doesn't send the string to the server, or the client when it should. The other problem, is in his code, it empties the strings "to avoid duplication" it says, but that just makes it so you can't type any more messages, lol. I guess that can be easily fixed by just str_cpy'ing blank spaces back in though. The real issue is the networking code not working.
So, I tried writing my own functions/events (simplified version) to see if I could send the string, then have it displayed on the screen. It doesn't work either. It seems to me it's either not sending/receiving the string, or the event is not being triggered. Here's the simple code I wrote:
STRING* chatline01_str = "#50";
STRING* test_str = "TESTING 123!!!";
STRING* test2_str = "#50";
//Then of course, I have TEXT objects to display the strings
// I'm just omitting those to save space
....
function send_msg()
{
wait(1);
send_string(test_str);
wait(1);
}
function server_event(void* str,var id)
{
switch(event_type)
{
case EVENT_STRING:
wait(1);
send_string(test_str);
wait(1);
}
}
function client_event(void* str,var id)
{
switch(event_type)
{
case EVENT_STRING:
wait(1);
str_cpy(chatline01_str,test_str);
wait(1);
}
}
...
// Then I put these in a function loop which continually runs
// the whole time the program does...
on_esc = exit_app;
on_server = server_event;
on_enter = send_msg;
on_client = client_event;
My on_esc event works fine when I press esc, and runs my function that prompts the user with whether or not they intend to exit.
However, the code you see above will not pass the STRING to the server or client to display it on screen. Well, I really think the events aren't being triggered. If I type in chatline01_str in the console, it just adds "=" behind it. If I type in test_str, it adds "= TESTING 123!". You know what I mean. So it's obviously never reaching this:
str_cpy(chatline01_str,test_str);
And probably not even running the server event to send it in the first place. So, I'm kind of out of ideas now. I've tried putting the on_event code outside the loop, and in many different places. It does no good. I also tried the event functions without any parameters/args, tried some with and some without, different combinations, all of them with params/args, and it made no difference.