|
Author |
Topic: networking (working in proce55ing) (Read 530 times) |
|
madmerv Guest
|
networking (working in proce55ing)
« on: Nov 15th, 2003, 3:12am » |
|
when it loads into a browser locally the applet reports "not inited" and then after a pause begins to "load" :: here's the code though, works locally (if you cut+paste this code into a proce55ing window, it works!) but from export, locally, it wont work (bizarro!) question: note below that the random rects are always being drawn in the loop() -- why is it pausing, then?!!! you can try it here: http://www.madmerv.com/proce55ing/mudclient some small errors with the textbox displaying properly; also a question: why does the applet pause while waiting for an incoming stream? any suggestions as to improve this? it wouldn't be possible to animate it Code: // NiMUD Client 5.1a // 3d Java Overdraft Version // Written with proce55ing .0067 expert // Some of this code is based on // proce55ing by Benjamin Fry // and the architecture originated // in code supplied by edwardgeorge, a member of the proce55ing forum // It reads the data broadcasted from the server, obtaining it again in the same order: Socket s; BufferedReader in; PrintWriter out; String data; // Array to hold the incomming data from the net BFont Univers45; String workbuf[]; // last line splitString'd String out_buf = ""; // output buffer String old_buf = ""; // last sent command int count = 0; // number of lines displayed color ANSI; // Last ansi code set this line to.. int screen_size = 50; // screen size in lines boolean done = false; // done //String screen_buf[] = new String[screen_size]; // copy value from screen_size here void parse( String s ) { if ( s != null ) { println(s); if ( ++count >= screen_size ) { count = 0; fill(0); rect( 0, 0, 500, 460 ); // clear screen } // for ( int x = 0; x < 100 && x<s.length(); x++ ) { fill(160,100+count*2,count*5); // rect(200+x*4, 6*count, 200+(x*4)+4, 6*count+6 ); // } point( 10, 8 ); text( s, 10, 8 + 8 * count ); // } } else count = screen_size; /* top conditional */ } void start_net() { try{ s = new Socket("mugs.net",2000); in=new BufferedReader(new InputStreamReader(s.getInputStream())); out=new PrintWriter(s.getOutputStream()); } catch(IOException e){println("IO EXCEPTION Err "+e);} } void setup() { size(640, 480); smooth(); background(0,0,0); rectMode(CORNER); textMode(ALIGN_LEFT); Univers45 = loadFont("Meta-Bold.vlw.gz"); textFont(Univers45,19); status("Connecting to NiMUD5.1a" ); textFont(Univers45,18); start_net(); } // // Continues forever; reading lines from the net // void loop() { // push(); // Update graphics //RANDOM RECTS (see above in message) //RANDOM RECTS //RANDOM RECTS //RANDOM RECTS fill(random(255),random(255),random(255)); rect( 500 + random(190), random(480), 640-random(140), 480-random(479) ); fill(255); try{ parse(in.readLine()); } catch(IOException e){println("IO EXCEPTION Err "+e);} print(">"); // out.flush(); // uncommenting this line causes memory errors // pop(); } // Redraw buffer void refresh_textbar( ) { fill(0); rect( 0, 460, 640, 480 ); // clear old stroke(255,255,255); fill(255,255,255); text( out_buf, 5, 460 ); text( out_buf, 5, 470 ); } void keyPressed( ) { println(key); switch(key) { case UP: out_buf = old_buf; break; case 10: out.println(out_buf); // Enter? out.flush(); old_buf = out_buf; out_buf = ""; break; case 8: if ( out_buf.length() > 1 ) out_buf = out_buf.substring(0,out_buf.length()-2); // Backspace? break; default: out_buf = out_buf + char(key); break; } refresh_textbar(); } // ------------------------------------------------------------------------ -- void mousePressed() { print("M"+mouseX+","+mouseY); }; |
|
|
« Last Edit: Nov 15th, 2003, 3:32am by madmerv » |
|
|
|
|
madmerv Guest
|
Re: networking (working in proce55ing)
« Reply #1 on: Nov 17th, 2003, 2:58am » |
|
i added an out.println(); above the out.flush() and got the graphics to update; but it does this in the main loop, so its slow... there must be some other way...!
|
|
|
|
Martin
|
Re: networking (working in proce55ing)
« Reply #2 on: Nov 25th, 2003, 6:19pm » |
|
"works locally (if you cut+paste this code into a proce55ing window, it works!) but from export, locally, it wont work (bizarro!)" networked applications using sockets need full system access. applets have security stuff in them that prevent you from doing this and other things. thus, they will only work with applications and not applets. 'run' runs the sketch as an application. exporting and opening it on a browser would mean running it as an applet.
|
|
|
|
|