|
If all your communicator threads do is receive messages and dump them in a queue for a different thread to handle...why not just use async sockets instead?
|
| # ? May 21, 2013 05:39 |
|
|
| # ? May 23, 2013 22:49 |
|
Night Shade posted:Which version of .NET are you targeting? If it's 4.5 or even 4.0 you have access to a whole bunch of things that will make your life much simpler. See: ConcurrentQueue<>, all the nice *Async methods on sockets etc. Also dedicated threads per socket doesn't scale particularly well, you're much better off doing Begin*(callback) / End*(IAsyncResult) or in 4.5 *Async because the thread pool does nice things under the hood to not poo poo up the scheduler. Ooh, those do look nice. I'll look through the documentation and see if I can figure out how to use them. quote:Also this statement is raising alarm bells: Ah, right, good catch. I was assuming that the "communicator" threads would be hogging the sockets while they were waiting to receive packets, but from looking at the asynch methods I've realized "blocking" doesn't mean what I thought it did. Jabor posted:If all your communicator threads do is receive messages and dump them in a queue for a different thread to handle...why not just use async sockets instead? Because I didn't realize the option was there. Okay, revised description. Two main threads. One's got a TcpListener in a loop, waiting for incoming connections. When it gets one, it assigns it a socket, puts the socket into some kind of thread-safe collection, and then calls BeginReceive on the socket (with an appropriately-chosen callback method to grab the incoming packets and stuff them in a BlockingCollection). The other thread is watching the BlockingCollection, grabs whatever comes out of it, does its game-state-adjustment magic, and then uses the same sockets to Send the updates out. Is there anything in there that blatantly Won't Work? Because I think I can manage that implementation.
|
| # ? May 21, 2013 05:48 |
|
So, I'm having a newbie (I hope) problem that I can't figure out. I have a webapp that works correctly within VS2012 but when I deployed to IIS8 forms submit stopped working. Let's say I'm in http://localhost:8080/Account/Register, when I click the submit button it tries to send me to http://account/Register/Post which doesn't make any sense. This seems like there's something wrong with my IIS config but it's 4 a.m and I can barely see. Any help will be appreciated. edit: turns out I'm a loving idiot and the form action was wrong. I don't know why it worked in VS. Polidoro fucked around with this message at May 21, 2013 around 07:21 |
| # ? May 21, 2013 06:53 |
|
Alien Arcana posted:Okay, revised description. Two main threads. One's got a TcpListener in a loop, waiting for incoming connections. When it gets one, it assigns it a socket, puts the socket into some kind of thread-safe collection, and then calls BeginReceive on the socket (with an appropriately-chosen callback method to grab the incoming packets and stuff them in a BlockingCollection). The other thread is watching the BlockingCollection, grabs whatever comes out of it, does its game-state-adjustment magic, and then uses the same sockets to Send the updates out. I can't think of anything off the top of my head, the only thing I would suggest is that you might be better off using traditional locking (=mutexes under the hood) around a regular List<Socket> instead of a thread-safe list of clients, primarily to avoid weird race conditions between clients connecting and the gamestate thread trying to push updates out. You're not really going to win much performance with a thread safe collection in that scenario because you're iterating over the whole set on gamestate updates anyway. I still think that you're going to be better served creating a client agent class to handle each socket rather than having your gamestate thread access them directly. For one, it'll mean socket error handling doesn't wind up making GBS threads up your game logic.
|
| # ? May 21, 2013 07:51 |
|
Alien Arcana posted:Okay, revised description. Two main threads. One's got a TcpListener in a loop, waiting for incoming connections. When it gets one, it assigns it a socket, puts the socket into some kind of thread-safe collection, and then calls BeginReceive on the socket (with an appropriately-chosen callback method to grab the incoming packets and stuff them in a BlockingCollection). The other thread is watching the BlockingCollection, grabs whatever comes out of it, does its game-state-adjustment magic, and then uses the same sockets to Send the updates out. Avoid threads until you need to address scalability/performance. Use async methods any time you want to have long-running, I/O-bound operations behave asynchronously. It'll totally eliminate the messy, bug-prone thread management.
|
| # ? May 21, 2013 12:55 |
|
I have a USB driver .dll that I've pulled in as a reference. It's exposing a function that I'm trying to use. The C#-specific docs don't list this function, but VS can see it. I've figured out the underlying types it's expecting and the function call is 'succeeding' in that it isn't complaining about mismatched types any more. But the hardware isn't generating the transactions I'm expecting. I'm waiting on approval for their official forums, is there any way to get into the disassembly for the .dll now? Passing in a struct (copied from the C++ docs) seems error-prone, and if it's as simple as reordering those arguments I can probably wing it. My naive attempts at "step into" haven't gone into the .dll.
|
| # ? May 21, 2013 16:04 |
|
JawnV6 posted:is there any way to get into the disassembly for the .dll now? ILSpy, although the site seems to be down right now.
|
| # ? May 21, 2013 16:13 |
|
JawnV6 posted:I have a USB driver .dll that I've pulled in as a reference. It's exposing a function that I'm trying to use. The C#-specific docs don't list this function, but VS can see it. I've figured out the underlying types it's expecting and the function call is 'succeeding' in that it isn't complaining about mismatched types any more. But the hardware isn't generating the transactions I'm expecting. What kind of a DLL is this? You mentioned C++ docs. That makes me think that maybe it's a native COM DLL and VS has found its type library or something like that. It's hard to get interop right. I start by using Jared Parson's "pinvoke assistant", and I look on pinvoke.net. It might help if you post the C++ here, and the way you're currently using it from C#. (if it is a native DLL, then you can always get disassembly from within VS - Project>Properties>Debugging>EnableUnmanagedDebugging, then Debug>Windows>Disassembly - but it probably won't help much...)
|
| # ? May 21, 2013 16:46 |
|
ljw1004 posted:(if it is a native DLL, then you can always get disassembly from within VS - Project>Properties>Debugging>EnableUnmanagedDebugging, then Debug>Windows>Disassembly - but it probably won't help much...) There are C#/VB docs for a subset of the functions and I've done alright with this tool so far. I'm perfectly comfortable with x86 assembly and have a very good idea of what I'm expecting it to do. Really seems like it's kicking back without attempting to talk to the hardware (would've seen status LED flash) so I think it was a check like if(dataSize==0) return;. I messed around with 'fixed' in the struct, put 'unsafe' around the required areas, got that building and it still wasn't acting right. That being said, I got the "low speed" version of this wonky function working and clocking in under ~2ms, so banging on the high-speed version with the struct isn't necessary. Thanks for the pointers, I'll dig in on that later today if I can find time.
|
| # ? May 21, 2013 16:58 |
|
Edit: yeah this is a really new page... You could go balls out and use SignalR. http://shootr.signalr.net/
|
| # ? May 21, 2013 17:55 |
|
So I'm not sure if this should go in this thread, the C++ thread, or the Coding Horrors thread but I'll post it here. I have a WCF web service that is calling an unmanaged C++ class through managed C+. I've looked at the code and have run unit tests against the managed C++ class and it doesn't seem to be leaking or crashing. However, when I fire up the Visual Studio test server to test the actual WCF service everything runs fine until I try to close the dev server after testing the service which makes the server crash. I'm not sure what this means or what effect this will have once I deploy the service to IIS. Also, if there is a better way of interoperating with the unmanaged class that I'm not using that would be helpful too.
|
| # ? May 22, 2013 21:28 |
|
EDIT-Figured it out. I moved my WWW rule to the very bottom, and explicitly make my other rules redirect to the www version and then stop processing. Leaving original question in for posterity. This is kind of an iis 7 config question, but it involves a web.config so I thought I'd ask here. I'm doing some redirecting after moving a site from php to aspx, and a preference for http://www. from non-www. The easy stuff is done (e.g. index.php => default.aspx, etc.), but I'm running into a problem where I get a 'double' redirect some of my more complicated patterns. So what happens is: code:code:code:code:code:Scaramouche fucked around with this message at May 23, 2013 around 00:21 |
| # ? May 22, 2013 21:38 |
|
I am still really bad at C#, but think I have finally worked the following out and don't want to get confused by being wrong. I'm sure that may overall approach to this problem could be far better but this is quite an important aspect of OOP. So, is this correct: I have a 2d array of int lists code:code:
|
| # ? May 23, 2013 12:53 |
|
pointsofdata posted:I am still really bad at C#, but think I have finally worked the following out and don't want to get confused by being wrong. I'm sure that may overall approach to this problem could be far better but this is quite an important aspect of OOP. So, is this correct: First off, rethink your data structure. Is there a class you can define that better represents your domain model? Second, why do you need a copy? A really silly, inefficient way to "deep copy" an object is to serialize it and deserialize it. But before you do that, let's see if we can't remove the need for the copy.
|
| # ? May 23, 2013 13:19 |
|
To be honest, you should just implement the deep copy yourself for practice if you're new to C#. Libraries are like calculators: they are totally necessary and you'll waste your time without one, but you should learn the ropes without them (at least, for simple stuff) so that you understand the underlying math (in this case, programming). If a deep copy of an array is something you have to think about, you need more practice.
|
| # ? May 23, 2013 13:35 |
|
Ithaqua posted:First off, rethink your data structure. Is there a class you can define that better represents your domain model? It's for a Sudoku solver (I need to teach myself proper programming for a project next year, so am trying to do so through a combination of a course book and project Euler). I started one without properly thinking about the logic required to solve one and got as far as an "easy" sudoku solver then realised that the method I had intended to use to solve harder ones might not work for all allowed problems, and wasn't sure if I could prove it either way. So I read some papers about it and indeed you pretty much have to use backtracking, which I am now, perhaps foolishly, trying to do a naive implementation of on top of my existing code (I think that this might be a bad idea and I'd be better of restarting, but the original question still felt important and I think this should work). An array containing a list of the allowed value for each cell was the data structure which immediately came to mind but am very open to better ways of doing it. My reason for wanting an independent copy was because I was planning to implement backtracking like this: 1. Reduce possible values to minimum using existing easy sudoku solver method Make a class which does the following: 2. In one cell test one of the allowed values, solve as much as possible using method from 1 a)If this works then great, either you've finished or can do 2 again b)If this breaks a Sudoku rule then try 2 with a different allowed value in that cell. This is how I think backtracking is meant to work but I could be wrong. The issue is that you can 2 -> 2a) -> 2 for a little while before failing and having to go back. I was going to do it by making a method in the solver class which creates a local copy of the array passed to it does 2 to it, passing on its own modified copy of the array to a new instance of the solver class if it works, or telling the instance which called it that it has failed if it doesn't work. I realise that this would in the case of very hard problems create a large number of instances of the solver, but think it will be fast enough as the grid only contains 81 cells and normally several will be filled with each iteration. I'm bad at this so am very open to criticism. What I am trying to describe is described better here: F. Crook: A Pencil-And-Paper Algorithm for Solving Sudoku Puzzles. Crook’s 2009 paper describing his algorithm for solving Sudoku puzzles. Available from http://www.ams.org/notices/200904/rtx090400460p.pdf . Just without the preemptive set stuff which seemed unnecessary for a computational implementation. Orzo posted:To be honest, you should just implement the deep copy yourself for practice if you're new to C#. Libraries are like calculators: they are totally necessary and you'll waste your time without one, but you should learn the ropes without them (at least, for simple stuff) so that you understand the underlying math (in this case, programming). If a deep copy of an array is something you have to think about, you need more practice. I agree, just wanted to check I'm not making other fundamental errors (or rather find out which ones I am making)/missing something which would allow me to reach my current goal. pointsofdata fucked around with this message at May 23, 2013 around 13:55 |
| # ? May 23, 2013 13:51 |
|
I found a hidden corner of the codebase that I was unfamiliar with and a pattern that bothered me. They'd built a logger that implemented IDispose, and had the DIspose() method do quite a bit of work generating the log entries. Then everywhere they wanted logging they'd wrapped things in a using() statement. Is there something wrong with this I can explain to them, other than "it's kind of ugly"? I know Dispose() is supposed to be used to clean up unmanaged resources. Are there unintended consequences of using it for something else?
|
| # ? May 23, 2013 14:21 |
|
No, there's nothing special about dispose. It's just a method on an interface (albeit, a special interface that there's some syntactic sugar around with using). Does the logger do timing with a stopwatch and output performance? Because I've seen and used that pattern before, it's actually quite succinct and useful: code:
|
| # ? May 23, 2013 14:25 |
|
Hey MVC/Web guys. How do you guys handle (or have your ever handled) a case where the business is asking you to generate page elements completely dynamically without resorting to long if/elses? In this application there could be as few as 2 tables on a page or a whole slew of them, and the order of them needs to be different based on which department the user is in AND the role within that department. Of course the VP of AppDev says that "we can make it completely generic and dynamic" without any sort of direction as to how. Generating HTML/Razor on the fly with custom Helpers/jQuery? That's where my head is at right now, but it's gonna be a bitch, I think..
|
| # ? May 23, 2013 15:24 |
|
Orzo posted:Does the logger do timing with a stopwatch and output performance? Because I've seen and used that pattern before, it's actually quite succinct and useful: Yes, it logs timing too. I guess It's all fine, I'm just so used to seeing Dispose() only handle releasing unmanaged resources that this usage threw me off a bit. Thank you.
|
| # ? May 23, 2013 15:37 |
|
aBagorn posted:Hey MVC/Web guys. How do you guys handle (or have your ever handled) a case where the business is asking you to generate page elements completely dynamically without resorting to long if/elses? The requirement is too vague. You probably don't want to dynamically generate HTML, that's a bitch to develop, test, and maintain. You could have a model that contains something structured along these lines (off the top of my head): code:Ithaqua fucked around with this message at May 23, 2013 around 16:04 |
| # ? May 23, 2013 16:00 |
|
|
| # ? May 23, 2013 22:49 |
|
Ithaqua posted:The requirement is too vague. You probably don't want to dynamically generate HTML, that's a bitch to develop, test, and maintain. Yeah, vaguery is abound with this project. I do like this approach below Ithaqua posted:
This should be able to give me what I want. Good call on the partial views, I was thinking along the same lines
|
| # ? May 23, 2013 16:10 |
















