Daily Archives

Articles indexed Saturday May 8 2010

Page 16/78 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • Odd performance with C# Asynchronous server socket

    - by The.Anti.9
    I'm working on a web server in C# and I have it running on Asynchronous socket calls. The weird thing is that for some reason, when you start loading pages, the 3rd request is where the browser won't connect. It just keeps saying "Connecting..." and doesn't ever stop. If I hit stop. and then refresh, it will load again, but if I try another time after that it does the thing where it doesn't load again. And it continues in that cycle. I'm not really sure what is making it do that. The code is kind of hacked together from a couple of examples and some old code I had. Any miscellaneous tips would be helpful as well. Heres my little Listener class that handles everything (pastied here. thought it might be easier to read this way) using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; namespace irek.Server { public class Listener { private int port; private Socket server; private Byte[] data = new Byte[2048]; static ManualResetEvent allDone = new ManualResetEvent(false); public Listener(int _port) { port = _port; } public void Run() { server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, port); server.Bind(iep); Console.WriteLine("Server Initialized."); server.Listen(5); Console.WriteLine("Listening..."); while (true) { allDone.Reset(); server.BeginAccept(new AsyncCallback(AcceptCon), server); allDone.WaitOne(); } } private void AcceptCon(IAsyncResult iar) { allDone.Set(); Socket s = (Socket)iar.AsyncState; Socket s2 = s.EndAccept(iar); SocketStateObject state = new SocketStateObject(); state.workSocket = s2; s2.BeginReceive(state.buffer, 0, SocketStateObject.BUFFER_SIZE, 0, new AsyncCallback(Read), state); } private void Read(IAsyncResult iar) { try { SocketStateObject state = (SocketStateObject)iar.AsyncState; Socket s = state.workSocket; int read = s.EndReceive(iar); if (read > 0) { state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, read)); if (s.Available > 0) { s.BeginReceive(state.buffer, 0, SocketStateObject.BUFFER_SIZE, 0, new AsyncCallback(Read), state); return; } } if (state.sb.Length > 1) { string requestString = state.sb.ToString(); // HANDLE REQUEST HERE // Temporary response string resp = "<h1>It Works!</h1>"; string head = "HTTP/1.1 200 OK\r\nContent-Type: text/html;\r\nServer: irek\r\nContent-Length:"+resp.Length+"\r\n\r\n"; byte[] answer = Encoding.ASCII.GetBytes(head+resp); // end temp. state.workSocket.BeginSend(answer, 0, answer.Length, SocketFlags.None, new AsyncCallback(Send), state.workSocket); } } catch (Exception) { return; } } private void Send(IAsyncResult iar) { try { SocketStateObject state = (SocketStateObject)iar.AsyncState; int sent = state.workSocket.EndSend(iar); state.workSocket.Shutdown(SocketShutdown.Both); state.workSocket.Close(); } catch (Exception) { } return; } } } And my SocketStateObject: public class SocketStateObject { public Socket workSocket = null; public const int BUFFER_SIZE = 1024; public byte[] buffer = new byte[BUFFER_SIZE]; public StringBuilder sb = new StringBuilder(); }

    Read the article

  • Resetting Globals With Importing

    - by what
    I have this code (Reset.py) that works how I want it to unless I import it. class Res(object): defaults={} class NoKey: pass def __init__(self): for key, values in defaults.items(): globals()[key]=values def add_defaults(key, values): Res.defaults[key]=value def remove_defaults(key=NoKey, remove_all=False): if remove_all: defaults={} else: del defaults[key] Without importing: >>> a=54 >>> Res.add_default('a', 3) >>> Res() <__main__.Res object at 0x> >>> a 3 >>> #great! :D With importing: >>> a=54 >>> Res.add_default('a', 3) >>> Res() <Reset.Res object at 0x> >>> a 54 This must mean when it is imported it changes the globals() under Reset and not __main__. How can I fix this?

    Read the article

  • integration of Asp.net and worpress blog

    - by vatsalit
    My website in asp.net. In this website when member register at that time wordpress blog will be created for that member. For another member another wordpress blog will be created for that member. When member change password in our means asp.net website also password will be change for his or her wordpress blog. It means asp.net is directly interact with wordpress blog. Is it possible? If yes then how it will be work? Please help me in detail. Thank you.

    Read the article

  • How can I remove all the files which has a string in a file

    - by michael
    Hi, I am trying to remove all the files in a directory hierarchy which a certain string inside the file (not the file name, it is the file content). I can list out all the file name which has a string in the file using 'grep -r -l mystringlooking for'. But how can I remove all the files returned by the grep ? I am trying this on ubuntu. Thank you.

    Read the article

  • What is your alternative to annotations?

    - by kunjaan
    Let us say Java didn't have annotations. What would be the ideas you would come up with to design something like Google Guice's DI framework? I am fairly new to Java and cannot think of anything other than what Junit3 Had XML Configuration Some kind of introspection? How would you inspect the elements that needed to be injected? What would be your ideal way of configuration other than annotations?

    Read the article

  • Parallel scroll textarea and webpage with jquery

    - by Roger Rogers
    This is both a conceptual and how-to question: In wiki formatting, or non WYSIWYG editor scenarios, you typically have a textarea for content entry and then an ancillary preview pane to show results, just like StackOverflow. This works fairly well, except with larger amounts of text, such as full page wikis, etc. I have a concept that I'd like critical feedback/advice on: Envision a two pane layout, with the preview content on the left side, taking up ~ 2/3 of the page, and the textarea on the right side, taking up ~ 1/3 of the page. The textarea would float, to remain in view, even if the user scrolls the browser window. Furthermore, if the user scrolls the textarea content, supposing it has exceeded the textarea's frame size, the page would scroll so that the content presently showing in the textarea syncs/is parallel with the content showing in the browser window. I'm imagining a wiki scenario, where going back and forth between markup and preview is frustrating. I'm curious what others think; is there anything out there like this? Any suggestions on how to attack this functionality (ideally using jquery)? Thanks

    Read the article

  • How to keep text inside a circle using Cairo?

    - by miguelrios
    I a drawing a graph using Cairo (pycairo specifically) and I need to know how can I draw text inside a circle without overlapping it, by keeping it inside the bounds of the circle. I have this simple code snippet that draws a letter "a" inside the circle: ''' Created on May 8, 2010 @author: mrios ''' import cairo, math WIDTH, HEIGHT = 1000, 1000 #surface = cairo.PDFSurface ("/Users/mrios/Desktop/exampleplaces.pdf", WIDTH, HEIGHT) surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT) ctx = cairo.Context (surface) ctx.scale (WIDTH/1.0, HEIGHT/1.0) # Normalizing the canvas ctx.rectangle(0, 0, 1, 1) # Rectangle(x0, y0, x1, y1) ctx.set_source_rgb(255,255,255) ctx.fill() ctx.arc(0.5, 0.5, .4, 0, 2*math.pi) ctx.set_source_rgb(0,0,0) ctx.set_line_width(0.03) ctx.stroke() ctx.arc(0.5, 0.5, .4, 0, 2*math.pi) ctx.set_source_rgb(0,0,0) ctx.set_line_width(0.01) ctx.set_source_rgb(255,0,255) ctx.fill() ctx.set_source_rgb(0,0,0) ctx.select_font_face("Georgia", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(1.0) x_bearing, y_bearing, width, height = ctx.text_extents("a")[:4] print ctx.text_extents("a")[:4] ctx.move_to(0.5 - width / 2 - x_bearing, 0.5 - height / 2 - y_bearing) ctx.show_text("a") surface.write_to_png ("/Users/mrios/Desktop/node.png") # Output to PNG The problem is that my labels have variable amount of characters (with a limit of 20) and I need to set the size of the font dynamically. It must fit inside the circle, no matter the size of the circle nor the size of the label. Also, every label has one line of text, no spaces, no line breaks. Any suggestion?

    Read the article

  • Asp.Net Cache, modify an object from cache and it changes the cached value

    - by Glen
    Hi, I'm having an issue when using the Asp.Net Cache functionality. I add an object to the Cache then at another time I get that object from the Cache, modify one of it's properties then save the changes to the database. But, the next time I get the object from Cache it contains the changed values. So, when I modify the object it modifies the version which is contained in cache even though I haven't updated it in the Cache specifically. Does anyone know how I can get an object from the Cache which doesn't reference the cached version? i.e. Step 1: Item item = new Item(); item.Title = "Test"; Cache.Insert("Test", item, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration); Step 2: Item item = (Item)Cache.Get("test"); item.Title = "Test 1"; Step 3: Item item = (Item)Cache.Get("test"); if(item.Title == "Test 1"){ Response.Write("Object has been changed in the Cache."); } I realise that with the above example it would make sense that any changes to the item get reflected in cache but my situation is a bit more complicated and I definitely don't want this to happen.

    Read the article

  • How to compile a Ubuntu Lucid kernel

    <b>My Thoughts Blog: </b>"The Ubuntu kernel developers have decided to change things up yet again for the Ubuntu Lucid kernel. The steps in this article will be significantly different from previous Ubuntu releases."

    Read the article

  • How to clear Windows disk read cache?

    - by Sebastiaan Megens
    For performance testing I need to clear Windows' disk read cache. I tried googling but I couldn't find anything other than rebooting or other manual stuff. Before I give in and do that, I'd like to know if anyone knows of a way to clear Windows disk read cache. I'm testing on Windows 7, but I'm also interested in Windows XP solutions.

    Read the article

  • Snow Leopard 10.6.3 Freezes Frequently

    - by Abhishek
    Snow Leopard 10.6.3 on my Macbook Pro freezes quite frequently now. It freezes for few seconds and then works fine. During that time trackpad does not work and keyboard works partially (missing keystrokes while I type). Initially it was once or twice in a day but now it has become quite frequent. Is somebody else facing similar issue?

    Read the article

  • should i link to a blog site or install my own blog engine?

    - by dc
    we're setting up a company blog. Our technology stack is .NET. Should we just use blogger/wordpress for the blog and redirect to it from our site? or should i install a blog engine directly on our site (e.g. blogEngine.NET)? some considerations i'd like feedback on are: 1.SEO - if you host your blog on wordpress/blogger instead of installing it on your site - will you get better page rankings? (if the content was the exact same) 2.scalability - i've read that dotNetBlogEngine doesnt scale well on web farms etc. our website is setup to be stateless. 3.security - presumably a hosted blog site has the advantage of having regular security updates. how easy is it to keep an installed blog engine patched? 4.examples of installed blog engines - dotNetBlogEngine seems to be the best but has a couple of limitations. can anyone suggest another one (n/a if you're advice is to host the blog on blogger/wordpress) 5.any other comments/issues/concerns we should be aware of? thanks for your feedback!

    Read the article

  • No Audio from Windows XP after formatting.

    - by karthik
    Hello folks, I have reinstalled in my Windows XP machine. After it is re-isntalled the audio in my machine has failed. I have installed all the device drivers in my mother board. The Realtek Sound driver is also installed. Note: Sound is working when I test the surround settings test in my RealTek program, but unable to play any audio, tried playing both in my local machine and from the internet.

    Read the article

  • Scheduling algorithm optimized to execute during low usage periods.

    - by The Rook
    Lets say there is a Web Application serving mostly one country. Because of normal sleep habits website traffic follows a Sine wave, where 1 period lasts 24 hours and the lowest part of the wave is at about midnight. Is there a scheduling algorithm optimized to execute during low usage periods? I am thinking of this as a liquid that is "pored into" this sine wave to flatten out resource usage. A ideal algorithm would take the integral of this empty space. If the same tasks need to be run daily the amount of resources consumed by previous executions could be used to predict future usage by looking at the rate in which resource usage is increasing. By knowing the amount of resources required this algorithm could fill in this empty space while leaving as much buffer as possible on either side such that its interference was reduced as much as possible. It would also be possible to detect if there isn't enough resources before execution begins, this opens the door for a cloud to help out. Does anything like this exist? Or should I build it into an existing scheduler like quartz and make it open source?

    Read the article

  • getting jpeg error

    - by bhaskaragr29
    <?php function LoadPNG() { /* Attempt to open */ //require_once 'resizex.php'; $imgname="/home2/puneetbh/public_html/prideofhome/wp-content/uploads/268995481image_11.png"; //$im = @imagecreatefrompng($imgname); $img= imagecreatefromstring(file_get_contents($imgname)); //$im=imagecreatefrompng('images/frame.png'); $im= imagecreatefromjpeg('images/frame.jpeg'); //imagealphablending($img, false); //imagesavealpha($img, true); //$img=resizex("$url",60,65,1); imagecopymerge($im,$img,105,93,0, 0,275,258,100); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } $img = LoadPNG(); header('Content-type: image/jpeg'); imagejpeg($im); imagedestroy($im); imagedestroy($img); ?> i am getting error arning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home2/puneetbh/public_html/prideapp/frame.php on line 11 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'images/frame.jpeg' is not a valid JPEG file in /home2/puneetbh/public_html/prideapp/frame.php on line 11 Warning: imagecopymerge(): supplied argument is not a valid Image resource in /home2/puneetbh/public_html/prideapp/frame.php on line 16 Warning: Cannot modify header information - headers already sent by (output started at /home2/puneetbh/public_html/prideapp/frame.php:11) in /home2/puneetbh/public_html/prideapp/frame.php on line 34 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home2/puneetbh/public_html/prideapp/frame.php on line 35 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home2/puneetbh/public_html/prideapp/frame.php on line 36

    Read the article

  • Java - SwingWorker - problem

    - by Yatendra Goel
    I am developing a Java Desktop Application. This app executes the same task public class MyTask implements Callable<MyObject> { in multiple thread simultaneously. Now, when a user clicks on a "start" button, I have created a SwingWorker myWorker and have executed it. Now, this myWorker creates multiple instances of MyTask and submits them to an ExecutorService. Each MyTask instance has a loop and generates an intermediate result at every iteration. Now, I want to collect these intermediate results from each MyTask instances as soon as they are generated. Then after collecting these intermediate results from every MyTask instance, I want to publish it through SwingWorker.publish(MyObject) so that the progress is shown on the EDT. Q1. How can I implement this? Should I make MyTask subclass of SwingWorker instead of Callable to get intermediate results also, because I think that Callable only returns final result. Q2. If the answer of Q1. is yes, then can you give me a small example to show how can I get those intermediate results and aggregate them and then publish them from main SwingWorker? Q3. If I can't use SwingWorker in this situation, then how can I implement this?

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >