Last visit was: It is currently Thu Mar 28, 2024 8:53 pm


All times are UTC-05:00




Post new topic Reply to topic  [20 posts ] 
Author Message
 Post subject:Another question about CrissCross
PostPosted:Sun Oct 12, 2008 8:43 am 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Is there anyway to keep the CrissCross console attached to my prompt in Windows?
It always opens a separate console.

Also, I've rewritten my server code:
main.cpp:
Code:
/* * CrissCross * A multi-purpose cross-platform library. * * A product of IO.IN Research. * * (c) 2006-2008 Steven Noonan. * Licensed under the New BSD License. * */ #include "header.h" #include "webserver.h" Console *console = NULL; Server *inst = NULL; int init(string arg) { if(arg == "start") { console->WriteLine("Start web server"); inst = new Server(80); } else if(arg == "stop") { console->WriteLine("Stop web server"); } else if(arg == "help") { console->WriteLine("Usage: WebServer start | stop | help"); } return 0; } int RunApplication ( int argc, char **argv ) { console = new Console (); // Start your application here if (argc <= 1) { string usage = "Usage: WebServer start | stop | help"; console->WriteLine(usage); inst = new Server(80); } else{ init(argv[1]); } // End your application here. #ifdef TARGET_OS_WINDOWS system ( "pause" ); #endif delete console; return 0; }
webserver.cpp
Code:
#include "header.h" #include "webserver.h" Server::Server(int port) { TCPSocket * s = new TCPSocket(); s->Listen((unsigned short) port); Accept(s); } int Server::Accept(TCPSocket * a) { TCPSocket * s = a; TCPSocket * nulls = NULL; while(1) { string in; s->Accept(&nulls); &nulls->Read(in); if(in == "\0") { Respond(&nulls); } else { cout << in << endl; } } return 0; } int Server::Respond(TCPSocket * a) { #ifdef TARGET_OS_WINDOWS system ( "pause" ); #endif return 0; }
webserver.h:
Code:
#include "header.h" #ifndef WEBSERVER_H #define WEBSERVER_H enum HTTPMethod { OPTIONS = 0, //0 GET, //1 HEAD, //2 POST, //3 PUT, //4 TRACE, //5 CONNECT //6 }; class Server { public: Server(int port); // The constructor ~Server(); // The deconstructor int Accept(TCPSocket *a); int Respond(TCPSocket *a); int Parse(char* str[]); }; #endif
I'm getting the following errors:
Code:
webserver.cpp(17): error C2102: '&' requires l-value webserver.cpp(18): error C2664: 'Server::Respond' : cannot convert parameter 1 from 'CrissCross::Network::TCPSocket **' to 'CrissCross::Network::TCPSocket *'
Any ideas?

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sun Oct 12, 2008 2:08 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Quote:
Is there anyway to keep the CrissCross console attached to my prompt in Windows?
It always opens a separate console.
0.7.2 is coming out in less than a week. Let me know if the same thing happens with it.
Quote:
I'm getting the following errors:
Code:
webserver.cpp(17): error C2102: '&' requires l-value webserver.cpp(18): error C2664: 'Server::Respond' : cannot convert parameter 1 from 'CrissCross::Network::TCPSocket **' to 'CrissCross::Network::TCPSocket *'
Any ideas?
Code:
if(in == "\0") { Respond(&nulls); }
should be
Code:
if(in == "\0") { Respond(nulls); }

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sun Oct 12, 2008 3:54 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
I've changed it but I'm still getting the C2102 error for line 17:
Code:
&nulls->Read(in);
EDIT:

I've looked over tcpsocket.cpp and for the life of me cannot figure out why I'm getting this error. Maybe the doxygen documentation should be a bit more clear?

New webserver.cpp:
Code:
#include "header.h" #include "webserver.h" Server::Server(int port) { TCPSocket * s = new TCPSocket(); s->Listen((unsigned short) port); Accept(s); } int Server::Accept(TCPSocket * a) { TCPSocket * s = a; TCPSocket * nulls = NULL; while(1) { string in; s->Accept(&nulls); if(&nulls != NULL) { nulls->Read(in); if(in == "\0") { Respond(nulls); } } } return 0; } int Server::Respond(TCPSocket * a) { #ifdef TARGET_OS_WINDOWS system ( "pause" ); #endif return 0; }

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sun Oct 12, 2008 11:09 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Quote:
I've changed it but I'm still getting the C2102 error for line 17:
Code:
&nulls->Read(in);
The change is simple. Drop the '&'. I am guessing you aren't clear on how pointers work, or this error would be as plain as day.
Quote:
I've looked over tcpsocket.cpp and for the life of me cannot figure out why I'm getting this error. Maybe the doxygen documentation should be a bit more clear?
I agree there should be some examples for TCPSocket and UDPSocket usage, but again: you are missing some pretty basic knowledge here. I highly recommend looking at some C or C++ tutorial site and read up on what the '*' (indirection) and '&' (address of) operators actually do, and in what cases you use them. Before going much further in C/C++, this knowledge is absolutely essential.

I've added some comments to your code:
Code:
#include "header.h" #include "webserver.h" /* * Why not just make it Server::Server(unsigned short port)? You won't use * any other data type for a TCP or UDP port number. */ Server::Server(int port) { TCPSocket * s = new TCPSocket(); s->Listen((unsigned short) port); Accept(s); } int Server::Accept(TCPSocket * a) { TCPSocket * s = a; TCPSocket * nulls = NULL; while(1) { string in; s->Accept(&nulls); /* * This is a useless comparison. Let me phrase this comparison in plain English: * "Is the address of the variable 'nulls' a non-NULL pointer?" * The way to fix the comparison to do what you need is to again drop the '&', * and get this: 'if(nulls != NULL)'. In English: * "Does the variable 'nulls' contain a non-NULL pointer?" * These two questions are -very- different and will greatly affect the result. */ if(&nulls != NULL) { nulls->Read(in); if(in == "\0") { Respond(nulls); } } } return 0; } int Server::Respond(TCPSocket * a) { #ifdef TARGET_OS_WINDOWS system ( "pause" ); #endif return 0; }

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Mon Oct 13, 2008 5:57 am 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Whew, it lives! :D

Thanks, finally got a working socket program... now I just have to get it to send/receive data between the server and browser.
(And possibly take a few more trips to learncpp.com ;))
Code:
if(in == "") { cout << "Gotta respond now..." << endl; Respond(nulls); }
The problem is in that block somewhere, I don't have time to look for it right now, so if anyone sees it, I would be grateful.

I have school now, so I won't be able to do anything else until I get back.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Mon Oct 13, 2008 11:14 am 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Hint: The return value of 'Read' is not worthless.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Mon Oct 13, 2008 5:19 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Success! I have got it to talk!
Image

and...

Image

This is the first HTTP server ever that uses CrissCross. :)

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Last edited by eddieringle on Mon Sep 06, 2010 12:12 pm, edited 1 time in total.

Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Mon Oct 13, 2008 7:38 pm 
Literally Nine
User avatar
 

Joined:Tue Mar 01, 2005 9:00 am
Posts:1263
Good for you. Do you have any plans on what to do next, or is this more of an experience collection?


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Mon Oct 13, 2008 7:40 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
I want to at least get as far as a config file or parsing GET commands to serve files instead of hard coding the html.
But this is definitely a great experience for me. :)

EDIT: I've gone as far as a Google Code project to help plan out what I'm going to do, so this is beginning to be more of a job for me.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Tue Nov 04, 2008 5:47 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Okay, everything builds fine. I can get the server to server the page. However, when the program runs and I do not immediately connect via my browser, the program crashes with a segfault.

Didn't have this issue before, I believe it happens at "ccerr = s->Accept(&nulls)", but I'm not complelely sure.

Help would be appreciated. :)

EDIT: Oops, nevermind, I found it, I was telling the server to close the connection when there was no connection to close. :oops:
Code:
int Server::Accept(TCPSocket * a) { TCPSocket * s = a; TCPSocket * nulls = NULL; while(1) { string in; int ccerr; ccerr = s->Accept(&nulls); if (ccerr == CC_ERR_WOULD_BLOCK) cout << "Non-blocking Sockets are enabled..."; if(ccerr == 0) { // If Accept(&nulls) responded with CC_ERR_NONE cout << "Reading from socket..." << endl; if(nulls->Read(in) == 0) { cout << in << endl; cout << "Gotta respond now..." << endl; Respond(nulls); } else { cout << "Error with Reading?" << endl; } } nulls->Close(); ThreadSleep(50); } return 0; }

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Wed Nov 05, 2008 2:44 am 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
When creating the console do this:
Code:
console = new Console(stdout, stdin);
That will prevent it from allocating a console window.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sat Nov 08, 2008 3:44 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Yes, I'm using that now.

I've switched to c-style strings for my Config reader, but when I try to read from the file I get a segfault.

Anyone know what's wrong?
Code:
int Server::ReadConfig() { char *l; FileReader *f = new FileReader(); f->Open("inceku.conf"); while (!f->EndOfFile()) { f->ReadLine(l,50); } return 0; }

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sat Nov 08, 2008 5:32 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Did you even read the documentation for ReadLine()?

First parameter is your preallocated buffer. Second parameter is the size of that buffer.
Quote:
Reads a line of data.

Parameters:
_buffer A character buffer for the data to be stored in.
_bufferLength The length of the buffer specified in _buffer.

Returns:
The number of bytes read.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sat Nov 08, 2008 5:34 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Yeah, I did read it, but I'm not sure I understand it.

Either way, I found a nice little StringTokenizer for C++ strings, and I got that to work, but if we can solve this problem, then that would be great too.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Another question about CrissCross
PostPosted:Sat Nov 08, 2008 5:37 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
I personally see no reason to use C++ STL strings. C-style strings are as simple as can be and if you use them right, performance is generally better than what you'd get with C++ STL strings.

_________________
- Tycho

Image


Top
Offline  
Display posts from previous: Sort by 
Post new topic Reply to topic

All times are UTC-05:00


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created by Miah with assistance from hyprnova