How would you do this?

AFB

Lifer
Jan 10, 2004
10,718
3
0
I'm making a very small NIO HTTP server. I have the networking code doen, I just need to figure out how to organize the client data and the headers. How would you manage the data for each client? Map? Another class and attach it to the key?
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
I use a "Connection" class attached to the key. Where that class knows/tracks what it needs and how to communicate with that specific client.

Was it the "it.remove()" that fixed your null pointer?
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Kilrsat
I use a "Connection" class attached to the key. Where that class knows/tracks what it needs and how to communicate with that specific client.

Was it the "it.remove()" that fixed your null pointer?

Amazingly yes, even thought I was already doing it just in a different place. *shrugs* I guess it's one of those things like hanging when you get the input stream before the output stream in some cases.

Anyway, thanks :beer:

Have any ideas about the headers? I think I might put the write method in the connection type class and have it handle the management of the headers.

Damn you have quick response time :D
 

Kilrsat

Golden Member
Jul 16, 2001
1,072
0
0
Originally posted by: amdfanboy
Originally posted by: Kilrsat
I use a "Connection" class attached to the key. Where that class knows/tracks what it needs and how to communicate with that specific client.

Was it the "it.remove()" that fixed your null pointer?

Amazingly yes, even thought I was already doing it just in a different place. *shrugs* I guess it's one of those things like hanging when you get the input stream before the output stream in some cases.

Anyway, thanks :beer:

Have any ideas about the headers? I think I might put the write method in the connection type class and have it handle the management of the headers.

Damn you have quick response time :D

Once the connection is accepted, I pawn all duties off onto the connection class. It keeps the server code more streamlined, and thus easier to fix. Once the server code says the key is writeable, it calls the write method of the connection, which may or may not actually write anything depending on the situation.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Kilrsat
Originally posted by: amdfanboy
Originally posted by: Kilrsat
I use a "Connection" class attached to the key. Where that class knows/tracks what it needs and how to communicate with that specific client.

Was it the "it.remove()" that fixed your null pointer?

Amazingly yes, even thought I was already doing it just in a different place. *shrugs* I guess it's one of those things like hanging when you get the input stream before the output stream in some cases.

Anyway, thanks :beer:

Have any ideas about the headers? I think I might put the write method in the connection type class and have it handle the management of the headers.

Damn you have quick response time :D

Once the connection is accepted, I pawn all duties off onto the connection class. It keeps the server code more streamlined, and thus easier to fix. Once the server code says the key is writeable, it calls the write method of the connection, which may or may not actually write anything depending on the situation.

Yeah, that was one of the options I was thinking about. It seeme the most logical because it kept the data where it would be used. So you kept the traditional loop in the in main server class and the called methods of the connection object you got from attachment(). Seems quite logical. I don't know, I find NIO to be confusing to work with.


Thanks again for your help :)