Search Amazon.com:
Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«369 »
  • Post
  • Reply
Jabor
Jul 16, 2010

#1 Loser at SpaceChem

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?

Adbot
ADBOT LOVES YOU

Alien Arcana
Feb 14, 2012



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:


Sockets are two-way, and any server-client communications should go over the same socket the client connected to the server with.

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. My education was originally in C++.


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.

Polidoro
Jan 5, 2011


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

Night Shade
Jan 13, 2013


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.

Is there anything in there that blatantly Won't Work? Because I think I can manage that implementation.

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.

Ithaqua
Jul 18, 2003

Only in Kenya.

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.

Is there anything in there that blatantly Won't Work? Because I think I can manage that implementation.

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.

JawnV6
Jul 4, 2004

so hot...



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.

Ithaqua
Jul 18, 2003

Only in Kenya.

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.

ljw1004
Jan 18, 2005

rum


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.
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.

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...)

JawnV6
Jul 4, 2004

so hot...



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.

Dietrich
Sep 11, 2001

Bullshit detected sir!


Edit: yeah this is a really new page...

You could go balls out and use SignalR.

http://shootr.signalr.net/

Ochowie
Nov 9, 2007



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.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

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:
olddomain.com/category_55.html
Redirects to:
code:
[url]www.olddomain.com/category_c55.html[/url]
And then to:
code:
[url]www.olddomain.com/category_c55.aspx[/url]
It's doing this because I have one rule that runs and intercepts www versus non-www:
code:
<rule name="Redirect to WWW" stopProcessing="false">
   <match url=".*" />
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
     <add input="{HTTP_HOST}" pattern="^olddomain.com$" />
   </conditions>
   <action type="Redirect" url="http://www.olddomain.com/{R:0}" redirectType="Permanent" />
</rule>
And then my specific rule that handles these category pages:
code:
<rule name="CategoryPages" stopProcessing="true">
    <match url="^([a-z0-9/-]+)_c([0-9]+).html$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Redirect" url="category-{R:1}-c-{R:2}.aspx" appendQueryString="true" />
</rule>
Ideally, I'd like to make this a one-step redirect for SEO reasons, but it doesn't seem to be working. I've tried adding 'olddomain.com/' in front of '([a-z0-9/-]+)_c([0-9]+).html', but that doesn't work since by default the rule accepts input of 'url path after '/''. I've also included the {HTTP_HOST} input into my rule, but then I get an error saying I can't use wildcards (The expression "*" contains a repeat expression) in the match url. I was hoping that some of you guys are rewrite experts and can help me figure out how to do this, since currently I kind of have to test against the live production environment, and every time the rule is messed up it errors out the whole site. This is also the first time I've wrestled with iis7 redirecting so there's some assumptions underlying all this that I'm not familiar with.

Scaramouche fucked around with this message at May 23, 2013 around 00:21

pointsofdata
Apr 25, 2011



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:
List<int>[,] Foo = new List<int>[9,9];
I want to pass this array as a parameter to a (constructor) method and have the constructed class do some stuff to its own local copy of the array. I.e. I make an array, A, pass it to a constructor for an instance of a new class and be able to have that new instance do stuff to its own copy of the array, B, that does not change the original array A. I think that this will not work:
code:
public Constructor (List<int>[,] originalArray)
        {
	    List<int>[,] newArray = new List<int>[9,9]
            newArray = originalArray; //This just passes a reference to the original array
        }
and nor will using using the Clone() method as this will just copy references to the lists. So I think that I have to implement what seems to be called a Deep Copy of the array. I think I can do that but is a library method I'm overlooking or somehting?

Ithaqua
Jul 18, 2003

Only in Kenya.

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:

I have a 2d array of int lists
code:
List<int>[,] Foo = new List<int>[9,9];
I want to pass this array as a parameter to a (constructor) method and have the constructed class do some stuff to its own local copy of the array. I.e. I make an array, A, pass it to a constructor for an instance of a new class and be able to have that new instance do stuff to its own copy of the array, B, that does not change the original array A. I think that this will not work:
code:
public Constructor (List<int>[,] originalArray)
        {
	    List<int>[,] newArray = new List<int>[9,9]
            newArray = originalArray; //This just passes a reference to the original array
        }
and nor will using using the Clone() method as this will just copy references to the lists. So I think that I have to implement what seems to be called a Deep Copy of the array. I think I can do that but is a library method I'm overlooking or somehting?

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.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!


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.

pointsofdata
Apr 25, 2011



Ithaqua posted:

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.

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

Dromio
Oct 16, 2002
Sleeper

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?

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!


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:
using(new PerformanceLogger())
{
  //do stuff
}
//when stuff is over, the instance of the performance logger automatically outputs timing info in the dispose method

aBagorn
Aug 26, 2004


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..

Dromio
Oct 16, 2002
Sleeper

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:
code:
using(new PerformanceLogger())
{
  //do stuff
}
//when stuff is over, the instance of the performance logger automatically outputs timing info in the dispose method

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.

Ithaqua
Jul 18, 2003

Only in Kenya.

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?

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..

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:
ReportModel
	List<ReportTable>

ReportTable
	List<ReportRow>

ReportRow
	List<KeyValuePair<string, string>>
So you have a model that has multiple tables, which in turn has multiple rows, which in turn has multiple columns with name/data. Then you can create partial views that dynamically render each table/row. The ordering of the data is a business rule and has no place in your presentation layer. When you're generating your report model is the time that you figure out what data to include and in what order.

Ithaqua fucked around with this message at May 23, 2013 around 16:04

Adbot
ADBOT LOVES YOU

aBagorn
Aug 26, 2004


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:


You could have a model that contains something structured along these lines (off the top of my head):
code:
ReportModel
	List<ReportTable>

ReportTable
	List<ReportRow>

ReportRow
	List<KeyValuePair<string, string>>
So you have a model that has multiple tables, which in turn has multiple rows, which in turn has multiple columns with name/data. Then you can create partial views that dynamically render each table/row. The ordering of the data is a business rule and has no place in your presentation layer. When you're generating your report model is the time that you figure out what data to include and in what order.

This should be able to give me what I want. Good call on the partial views, I was thinking along the same lines

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«369 »