Example
#{example}"); ipb.editor_values.get('templates')['togglesource'] = new Template(""); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
Emoticons
"); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]10 Replies - 88 Views - Last Post: Yesterday, 07:59 PM
#1
Reputation: 0
- Posts: 10
- Joined: 06-August 12
Posted Yesterday, 02:19 PM
Hey there guysI just finished reading Head First Java and I'm embarking on my first ever coding project. A chat server with many different functions, server settings, permissions etc. The server will have its hideable GUI as well that I can use to check stats, manage connections etc.
All of the commands on the server need to be callable from the client. So I'm wondering exactly if I've got the right idea as far as detecting server commands goes.
For all string data that a client sends me, first I have to detect whether it's a server command or just a regular old message by checking every string for whether it starts with "//"...
If it does, then I check for the command and check it against command functions on the server, then IF it's a server command that takes another string parameter ie "//kick retard", check for that string and then check it against the user list and act accordingly.
I also wanna have a GUI that is also completely capable of doing these kind of functions too but I'll figure that out later.
So if that's all right, I just have one other major concern... I read in my book that Strings that get unassigned from their references just SIT THERE AND NEVER GO AWAY EVER. GAH. So is it a valid concern that say if my chat server is running indefinitely, say for weeks at a time on a host machine, then every single string operation handled by the server (ie all commands and all chat strings) are just gonna pile up and pile up in memory until the host machines ram explodes? Obviously this is something that I CAN'T allow my server to do, so how exactly do I avoid this problem? So far I've heard about StringBuilder/StringBuffer but HFJ only touched on that so I don't actually know anything *about* it. I will look into it and my best guess is that using SBuild/SBuf is the solution but I'm not 100% and need that confirmed.
Also if that is true, doesn't that make it risky using *any* regular String operations on the server *at all*?
Any answers appreciated much
Is This A Good Question/Topic? 0
Replies To: Building a chat server/client
#2
Reputation: 2026
- Posts: 8,451
- Joined: 20-September 08
Re: Building a chat server/client
Posted Yesterday, 02:27 PM
#3
Reputation: 5215
- Posts: 8,214
- Joined: 19-March 11
Re: Building a chat server/client
Posted Yesterday, 02:32 PM
Swanny, on 11 April 2013 - 04:19 PM, said:
I read in my book that Strings that get unassigned from their references just SIT THERE AND NEVER GO AWAY EVER. GAH.
Well, no, they shouldn't do that. That's what the garbage collector is for.
#4
Reputation: 0
- Posts: 10
- Joined: 06-August 12
Re: Building a chat server/client
Posted Yesterday, 02:53 PM
jon.kiparsky, on 11 April 2013 - 02:32 PM, said:
Swanny, on 11 April 2013 - 04:19 PM, said:
I read in my book that Strings that get unassigned from their references just SIT THERE AND NEVER GO AWAY EVER. GAH.
Well, no, they shouldn't do that. That's what the garbage collector is for.
I'm reading under String immutability in the HFJ appendix that say if I were to do this operation:
String s="0"; for(int x = 1; x < 10; x++){ s = s + x; }
Apparently it would create strings through from 01, 012, 0123... to 0123456789 and end up having s assigned to the latter, but all of those first nine strings would still be in the 'string pool,' and it's saying that the garbage collector *doesn't* go to the string pool to clear away unassigned strings. That's my concern.
#5
Reputation: 516
- Posts: 1,596
- Joined: 29-July 11
Re: Building a chat server/client
Posted Yesterday, 02:54 PM
Even if that is true, those string take up such little memory that it isn't even worth worrying about.
#6
Reputation: 5215
- Posts: 8,214
- Joined: 19-March 11
Re: Building a chat server/client
Posted Yesterday, 03:01 PM
As I understand it, the string pool contains strings existing at compile time - so your loop wouldn't intern those strings. I could be wrong, but that's how I believe it works.Interning does lead to some interesting effects, and some counterintuitive ones. I'll have to go back and review a little before I try to say anything definitive about it, though.
#7
Reputation: 0
- Posts: 10
- Joined: 06-August 12
Re: Building a chat server/client
Posted Yesterday, 03:10 PM
farrell2k, on 11 April 2013 - 02:54 PM, said:
Even if that is true, those string take up such little memory that it isn't even worth worrying about.
Yeah. It's saying that the main function of immutability was to save memory on tiny devices like cell phones etc so even though it's unlikely to have a big impact, I think it's still something worth knowing about. I want my program to waste as little memory as possible
And thanks Jon I suppose if something like this were actually a big deal then people would know more about it so it might not be as big a concern as I thought it was.
#8
Reputation: 945
- Posts: 2,099
- Joined: 05-April 11
Re: Building a chat server/client
Posted Yesterday, 03:28 PM
Swanny, on 11 April 2013 - 09:53 PM, said:
jon.kiparsky, on 11 April 2013 - 02:32 PM, said:
Swanny, on 11 April 2013 - 04:19 PM, said:
I read in my book that Strings that get unassigned from their references just SIT THERE AND NEVER GO AWAY EVER. GAH.
Well, no, they shouldn't do that. That's what the garbage collector is for.
I'm reading under String immutability in the HFJ appendix that say if I were to do this operation:
String s="0"; for(int x = 1; x < 10; x++){ s = s + x; }
Apparently it would create strings through from 01, 012, 0123... to 0123456789 and end up having s assigned to the latter, but all of those first nine strings would still be in the 'string pool,' and it's saying that the garbage collector *doesn't* go to the string pool to clear away unassigned strings. That's my concern.
I haven't been able to find anything official about Java's string pool, but you do not have to worry about it
Java does garbage collect Strings. Some Strings live in the string pool, but that should hopefully never make you get any memory problems!
String s = "0"; //a copy of the constant "0" is saved in the string pool for(int x = 1; x < 10; x++){ //s = s + x; //Is like writing -> //Creates a new String object //Will not be saved in the string pool s = s.concat(x.toString()); }[
#9
Reputation: 0
- Posts: 10
- Joined: 06-August 12
Re: Building a chat server/client
Posted Yesterday, 03:33 PM
CasiOo, on 11 April 2013 - 03:28 PM, said:
Swanny, on 11 April 2013 - 09:53 PM, said:
jon.kiparsky, on 11 April 2013 - 02:32 PM, said:
Swanny, on 11 April 2013 - 04:19 PM, said:
I read in my book that Strings that get unassigned from their references just SIT THERE AND NEVER GO AWAY EVER. GAH.
Well, no, they shouldn't do that. That's what the garbage collector is for.
I'm reading under String immutability in the HFJ appendix that say if I were to do this operation:
String s="0"; for(int x = 1; x < 10; x++){ s = s + x; }
Apparently it would create strings through from 01, 012, 0123... to 0123456789 and end up having s assigned to the latter, but all of those first nine strings would still be in the 'string pool,' and it's saying that the garbage collector *doesn't* go to the string pool to clear away unassigned strings. That's my concern.
I haven't been able to find anything official about Java's string pool, but you do not have to worry about it
Java does garbage collect Strings. Some Strings live in the string pool, but that should hopefully never make you get any memory problems!
String s = "0"; //a copy of the constant "0" is saved in the string pool for(int x = 1; x < 10; x++){ //s = s + x; //Is like writing -> //Creates a new String object //Will not be saved in the string pool s = s.concat(x.toString()); }[
Thanks tons mate
It's good to know that I won't have to worry about this. If anything happens to happen by chance I'll come back n let you know but I'll get started on my program without worrying about this
+1
#10
Reputation: 5215
- Posts: 8,214
- Joined: 19-March 11
Re: Building a chat server/client
Posted Yesterday, 03:59 PM
Swanny, on 11 April 2013 - 05:10 PM, said:
farrell2k, on 11 April 2013 - 02:54 PM, said:
Even if that is true, those string take up such little memory that it isn't even worth worrying about.
Yeah. It's saying that the main function of immutability was to save memory on tiny devices like cell phones etc so even though it's unlikely to have a big impact, I think it's still something worth knowing about. I want my program to waste as little memory as possible />
And thanks Jon /> I suppose if something like this were actually a big deal then people would know more about it so it might not be as big a concern as I thought it was.
Good question to be asking, though. If you want to know about the underbelly of the beast, you might think about bookmarking the Java Language Spec and the JVM spec, both available from Oracle. Some of it is heavy going, but it defines the language and the machine pretty thoroughly.
#11
Reputation: 7849
- Posts: 30,663
- Joined: 06-March 08
Re: Building a chat server/client
Posted Yesterday, 07:59 PM
Swanny, on 11 April 2013 - 05:53 PM, said:
Apparently it would create strings through from 01, 012, 0123... to 0123456789 and end up having s assigned to the latter, but all of those first nine strings would still be in the 'string pool,' and it's saying that the garbage collector *doesn't* go to the string pool to clear away unassigned strings. That's my concern.
First I doubt that they won't be garbage collected... don;t know where you read tha urban legend
One thing for sure, this code is an horrible coding practice. StringBuilder and StringBuffer where not invented for nothing.. and actually are used behind the scene for those operations.
Anyhow, post the code of your first project, I am sure that I'll be able to point to you a lot of more horrible coding practices (this is my job)
Page 1 of 1
Source: http://www.dreamincode.net/forums/topic/318262-building-a-chat-serverclient/
Valerie Harper White Smoke Barcelona Kwame Kilpatrick New pope 2013 good morning america earthquake california
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন