|
Hello all!
I'm attempting to create an active connection to an ftp server without any success. Passive mode works fine, but I have a vendor that will not allow passive mode connections. So I use the PORT command that specifies my IP and then the port number to use and this succeeds, but when I try to send the data, the connection is out right refused.
I'm using FTPClient.cs which was posted on this site (I used *'s instead of the IP address at my company)
private Socket createDataSocket()
{
this.sendCommand("PORT *,*,*,*,7,130");
if ( this.resultCode != 200 ) throw new FtpException(this.result.Substring(4));
Socket socket = null;
IPEndPoint ep = null;
try
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
ep = new IPEndPoint(Dns.Resolve("*.*.*.*").AddressList[0], ((7 << 8) + 130));
socket.Connect(ep);
}
catch(Exception ex)
{
// doubtfull....
if ( socket != null && socket.Connected ) socket.Close();
throw new FtpException("Can't connect to remote server", ex);
}
return socket;
}
I then use the STOR command to write the file name on the server, which it completes, but then the data connection is refused.
Any thoughts?
|
|
|
|
|
How do you draw on the main menu bars background? Not the actual menu items themselves but the entire menu bar.
|
|
|
|
|
Ask in the ASP.NET forum, which is specific for ASP.NET-related questions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I have an object that has two events. I need to serialize this object, and somehow store the hooked-up event handlers that these events have. I can't just serialize the object with the events or a lot of other stuff will get serialized too, so I need to save the methods that are hooked up to these two events somehow.
Does anyone have a good approach to this? I've tried many things, but with no luck. Thanks in advance.
|
|
|
|
|
hello, I just want to write my own Regedit in C#, just start developening it for windows xp and then move to Windows CE .NET, but remaining in the contest of the thread, I saw that Registry's API are not implemented as method, so I think I shall use P-invoke?? my question is :
in C I've got
<br />
LONG RegOpenKey(<br />
HKEY hKey,<br />
LPCTSTR lpSubKey,<br />
PHKEY phkResult<br />
);<br />
I can do:
<br />
[DllImport("advapi32.dll")]<br />
public static extern int RegOpenKeyEx(System.UInt32 hKey, String lpSubKey, System.UInt32 ulOptions, System.UInt32 samDesired, System.UInt32 phkResult);<br />
1) I'm not sure if I've setted types correctly
2) how I define in C# code variable for phkResult? If I define it as UInt32 I can't do as I do in C &phResult...
Thanks in advance,
Paolo
|
|
|
|
|
Try the following:
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, EntryPoint="RegOpenKeyEx")]
static extern long RegOpenKeyEx(
IntPtr hKey,
String subKey,
uint options,
int sam,
out IntPtr phkResult);
- Nick Parker My Blog | My Articles
|
|
|
|
|
.NET already implements the registry API's.
Check the Microsoft.Win32.Registry class.
|
|
|
|
|
thanks you opened my eyes =), I was just playing around with that class but a new problem came at my hands...... if I want to use a recorsive function to process keys how I do that?? In Win32 API, I've RegEnumerateKey/Values here the most similar thing is String [] subkey = rk.GetSubKeyNames(); , so I do
<br />
private void AddRegNode(TreeNode node, RegistryKey root)<br />
{<br />
RegistryKey rk = root; <br />
String [] subkey = rk.GetSubKeyNames();<br />
if(subkey.Length==0) return;
foreach (String s in subkey)<br />
{<br />
String livia = rk.Name + "\\" + s;<br />
RegistryKey temp = Registry.CurrentUser.CreateSubKey(livia);<br />
TreeNode newNode = new TreeNode(s);<br />
this.Tree.SelectedNode.Nodes.Add(newNode);<br />
AddRegNode(newNode, temp);<br />
but doing so it doesn't work, first all the nodes are added to selected node, but I'l fix it, second it desn't go deeper ( HKEY_CURRENT_USER\AppEvents\EventLabels is max deep it reaches)
thanks
Paolo
|
|
|
|
|
I wrote a simple window application that fills a treeview with registry keys.
The code fills the tree with the registry keys (no values)
private void FillNode(TreeView treeView, TreeNode parentNode, RegistryKey key)
{
int index = key.Name.LastIndexOf("\\");
string keyname = key.Name;
if (index > 0)
{
keyname = key.Name.Remove(0, index + 1);
}
TreeNode node = null;
if (null == parentNode)
{
node = treeView.Nodes.Add(keyname);
}
else
{
node = parentNode.Nodes.Add(keyname);
}
string[] subkeyNames = key.GetSubKeyNames();
RegistryKey subkey = null;
foreach (string subkeyName in subkeyNames)
{
try
{
subkey = key.OpenSubKey(subkeyName);
}
catch (SecurityException e)
{
continue;
}
FillNode(treeView, node, subkey);
subkey.Close();
}
}
To use it call:
FillNode(treeView1, null, Microsoft.Win32.Registry.CurrentUser);
Where treeView1 is your TreeView control.
Notes:
1. If you read the keys them use OpenSubKey and not CreateSubKey
2. Make sure you catch exception. There are keys you cannot open.
3. Don't forget to close keys that you open.
Good luck,
Ami
|
|
|
|
|
Hello,
I have a datagrid with a list of customers. I want to be able to click on the row then be able to display the customer number which is in the first column of that row.
I have code for finding the row number:
rowNumber = grdDisplayCustomers.CurrentRowIndex;
But how do find out the customer number which is in the first column of that row.
Many thanks in advance,
Steve
|
|
|
|
|
You use either the DataView you might have assigned to the DataGrid , or get the CurrencyManager and query for the DataRow with that index. Don't simply use the DataSet or DataTable because after sorting the DataGrid those rows our out of sync. An example follows:
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
{
DataView view = cm.List as DataView;
if (view != null)
{
DataRowView rowView = view[rowIndex];
object value = rowView[0];
if (value != null) return value.ToString();
else return null;
}
} An IndexOutOfRangeException may be thrown in this sample at view[rowIndex] , but that should actually be a desired effect from this code (make sure you handle it, though).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello everybody!
I have the problem of effective implementation of multidimensional arrays in C#. In my application I'm using arrays with doubles as a fundamental structure. The number of dimensions and their length is known only in runtime, but typical array is approximately 4-10 dimensional with the length 1-15 for each dimension. Currently (because of historical reasons) these "arrays" are implemented as nested ArrayLists. This means there is a root-level ArrayList that contains "references" to the array lists of the second level and so on (the array list of the last level contains the double values).
Correspondly, if I want to get an element with "coordinates" [2, 3, 4, 5] in a 4-dimensional space I need to run through the levels of array list taking the arraylist with index 2 from the root list, from it the array list with index 3, from the last the array list with index 4, and from the very last array-list the double value with index 5. This is certainly quite ineffective, and I tested an alternative with built-in multidimensional array that is created with the following construction:
System.Array tempSpace = Array.CreateInstance(System.Type.GetType("System.Double"), allDimensions);
where allDimensions is a one-dimensional array with ints - dimensíons for my multidimensional space.
Suprisingly, I found only 2-3 times difference in comparison with implementation on array lists (I tested looping through all elements, incrementing all elements, random access. Code can be provided if needed).
I suspect that the performance problem with built-in multidimensional array is mainly occured by boxing/inboxing (I do not know how to create a multidimensional array so that it will not require boxing/inboxing not knowing the number of dimensions in compile-time). Accordingly, I have following questions:
1. Is it possible to create a multidimensional array so that it will not require boxing/inboxing not knowing the number of dimensions in compile-time? (type of elements is known in compile time - double).
2. If the answer on the second question is no, what will be the better implementation for multidimensional array of doubles of my size (4-10 dimensions with the length 1-15 of each dimension):
a) Built-in multidimensional arrays that suffer (supposedly) from boxing/inboxing.
b) Large one-dimension array, and I need to write some code for index managing (calculating the position of element in one-dimensional array that corresponds to the position in the multidimensional array given its indices).
c) Your solution.
So, with my solutions on the one hand I have boxing/unboxing issue, on the other hand - index managing (which also requires some computational resources) and my time for implementing the solution.
I expect the following functionality from the implementation:
1. Fast random access (write and read) basing on given indices characterizing the position in the multidimensional space (indices are not predictable - random).
2. Fast sequential access (write and read) basing on given indices. By "sequential" here I mean that I will start at some position of the space and get all "neighboring" positions sequentially in some dimension (get a slice from the space).
3. The dimensions of the array are quite rigid and basically are not changed after creation of the array. The increase of dimensions/length of dimension is never required, but there can be situations when I will set to zero a whole "slice" (whole dimension), if the amount of zeroed dimensions is high it may be advantegeous to "compress" the array. This is not a "need to be" thing, it will be always possible to realize it making a compressed array and copying elements to it.
4. It will be also not bad to have some method to efficiently set all elements of array to some value (0 or 1, for instance).
I would like to use only managed code. I have already read "Arrays Undocumented" article at http://www.codeproject.com/dotnet/arrays.asp
I would be glad to here any opinions on this topic, in particular answers on my questions. Thank you very much for your help.
Andrew Kuklin.
|
|
|
|
|
OT: You may want to be a little careful with the usage of language in a help forum, using wording like "I expect" sounds far too much like "I want this done for me", not as it should sound "I would like some help with this please" - the sentiment expressed in the last line of your post.
Anyhoo, It sounds to me like the functionality you are after is closer to a Binary tree than it is to a multidimensional array, maybe its worth you googling that and having a look.
Failing that would continuing with a M.D. ArrayList format encapsulated into an easy-to-use object not fit the bill?
|
|
|
|
|
Hello, J4amieC.
Probably, I've formulated what I wanted to say in a very inadequate way, by "I expect the following functionality from the implementation:" I meant "I would like to use the result solution for following purposes:". I do not want anyone to write code for me, I would like to hear some thoughts of people that are more experienced in this topic as I am.
Concerning your solution: at first, thank you for your help. Secondly, I'm afraid that I don't quite understand what you're proposing. I know what a binary tree is, what kind of data do you suggest to store in the nodes of the tree? Besides, I think it will be better to store minimum data for access to array (in your example with binary tree, I will need some kind of "links" to the children of parent node). I would like to give some estimation of typical "spaces" that are currently used. For example, a typical 10-dimensional array with following dimensions: {4, 7, 8, 6, 8, 2, 6, 7, 2, 7}. This will result (let's take 8 byte pro double-value) in
(4*7*8*6*8*2*6*7*2*7)*8 bytes=101154816 bytes=96,46875 Mb. And that is already quite big. I can have up to 10-20 of those "spaces". I just cannot throw away another 96 Mb for control structures. And of course Arraylist-based solution will not save the situation because of memory- and time overhead connected with boxing/unboxing.
Here is also the code with which I tested the performance. I've commented it as much as possible, but if anything is not clear, please, do not hesitate to ask:
//Create a test 10-dimensional array
int[] allDimensions = new int[10]{4, 7, 8, 6, 8, 2, 6, 7, 2, 7};
System.Array testArray = Array.CreateInstance(System.Type.GetType("System.Double"), allDimensions);
//currentDimensions is an array representing "counters" of dimensions
//I'll explain this on example. If as tempTable we have a three-dimensional array
//with allDimensions=[4, 8, 2].
//Then currentDimensions will run through the following combinations:
//[0; 0; 0], [1; 0; 0], [2; 0; 0], [3; 0; 0], [0; 1; 0], [1; 1; 0], [2; 1; 0] etc.
int[] currentDimensions = new int[allDimensions.Length];
//done variable checks whether all "places" of the space were visited
//(i.e. with the same example of three-dimensional array bool will be true when
//currentDimensions=[3, 7, 1]
bool done=false;
while(!done)
{
//Increment the current place in the space
double curValue = (double)testArray.GetValue(currentDimensions);
testArray.SetValue(++curValue, currentDimensions);
//Try to get the next combination of currentDimensions
done=true;
for(int j=0; j
|
|
|
|
|
I'm developing my first Managed DirectX app at the minute and although this isn't going to stop me moving on it might change my design ideas. All i want to know is which is quicker/more efficient after it's compiled.
Scenario 1.
public class Ball
{
public void DrawBall
{
}
}
public class Game
{
Ball ball = new Ball();
public void Draw()
{
ball.DrawBall();
}
}
or Scenario 2
public class Ball{}
public class Game
{
Ball ball = new Ball();
public void Draw()
{
}
}
So, which is faster or are they both the same speed?
Both will have the same draw code but scenario 1 does the drawing inside the ball.DrawBall method which is called from the class game.
Scenario 2 does the drawing inside the game class so there isn't the extra function call.
Bear in mind that this is gonna be done over 100 times a frame (potentially) and around 30 frames per second.
Hope someone out there knows.
Kev
|
|
|
|
|
I think this is more of a design structure question than a performance question. Imagine you have the scenario where you're drawing 2 teams of 11 players, a ball and 2 goals, would you want your code to look like this:
public class Game
{
public void Draw()
{
}
}
or this
public class Game
{
private Ball ball;
private Team team1;
private Team team2;
private Gaol goal1;
private Gaol goal2;
public void Draw()
{
ball.Draw();
team1.Draw();
team2.Draw();
goal1.Draw();
gaol2.Draw();
}
}
I dont know which is quicker, but for readability and to save having a very long method/list of methods in the game class I would go with the second option above.
|
|
|
|
|
I know that, i would rather use the second option myself, but the question is all about speed. If there is no speed difference then i will go with the more OO oriented approach because it's easier, but if it's slower then i will have to use the less readable first option.
Kev
|
|
|
|
|
If you are that concerned about speed why not write it in assembler?
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
2 Reasons.
1. I don't know assembler
2. That would defeat the object of me trying to learn Managed DirectX
Kev
|
|
|
|
|
why not loop through it 10^6 times to see which is faster?
there are no facts, only interpretations
|
|
|
|
|
second source is faster than first..
why ?
because in second source, construction operation is automated..
Oguz Bastemur
|
|
|
|
|
Hi,
We currently have a sutuation where we have a C# application and a MFC/C++ application.
To synchronize events between them we have used a Mutex. This is created with the following code:
mutexInterface = new System.Threading.Mutex(false, strMUTEX);
strMUTEX is a constant string used to name the Mutex.
On the MFC side the mutex is constructed with the following code:
m_muxInterfaceMutex(FALSE, strMUTEX);
Everything seems pretty simple so far.
If we start the MFC app first, then the C# one everything runs fine.
However if we run the C# app first the construction of the mutex in the MFC app fails and displays 'A required resource was unavailable'
Does anybody know how we can overcome this situation. We would rather avoid telling the users they have to start one app before the other, but it may come to that.
|
|
|
|
|
sjhart wrote:
We would rather avoid telling the users they have to start one app before the other, but it may come to that.
You could write a 3rd application/tiny script that starts both applications in the desired order you want them to be started.
--
Affordable Windows-based CMS: www.zeta-producer.de/enu
|
|
|
|
|
Do someone know a simple way to hook 2 forms to each other like winamp ?
I have a SDI application with a parent form from which i open child forms.
For example, in winamp there is the main window which is the player, then we can open the playlist.
We can move the playlist and put it where we want, but if we move it near the main window, it automaticaly sticks to it (like a magnet) then after, when we move the player, the playlist follow...
I would like my forms to do this magnet effect.
thanks
|
|
|
|
|
There is obviously no built-in way of doing this but you can always:
- keep track of where your forms are and the sizes of the forms
- respond to events when a form is moved
- calculate whether a form is close enough to "snap" and then move the form...
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|