|
using while loop,
string strMsg = "";
try
{
int nSize = 1024;
if (m_socket != null && m_socket.Connected)
{
byte[] btRec = new byte[nSize];
//受信したバイト数
int bytes=0;
//受信したバイト数よりバッファまで受信を繰り返し実行します
do
{
bytes = m_socket.Receive(btRec,0, nSize, SocketFlags.Partial);
//デコードされた表現を含んでいる文字列を返します
strMsg += Encoding.Default.GetString(btRec, 0, bytes);
}
while(bytes != nSize);
}
}
catch
{
}
return strMsg;
|
|
|
|
|
quote:
do
{
bytes = m_socket.Receive(btRec,0, nSize, SocketFlags.Partial);
strMsg += Encoding.Default.GetString(btRec, 0, bytes);
}
while(bytes != nSize);
bytes variable will store only how many bytes of the buffer have been written with the Receive call, I'm wrong? Some times ago I tested it, but in this way my program tried to store as much data as it could in the buffer... from MSDN:
"If you are using a connection-oriented Socket, the Receive method will read as much data as is available, up to the size of the buffer."
In this way I can't know if I've received one or more messages with a single receive all
|
|
|
|
|
i am also having problems with socket class.
i am creating a client/server using sockets (tcp Client and TCP listener) but i want to make it work over the internet bypassing a proxy server. is there any possible way that i could make my program run over the internet with this code?
thank you
<
//for my client class
try
{
ByPassProxy();
clientsocket = new TcpClient(serveraddress, serverport);
ns = clientsocket.GetStream();
sr = new StreamReader(ns);
connected = true;
}
public static void ByPassProxy()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:8080/STUFF//game.exe");
/*
GenerateGetOrPostRequest("http://localhost:8080/STUFF//game.exe",
"GET",
null);
*/
// add the proxy info
HwrAddProxy(request,"proxyaddress:port","username","password","domain");
// or set it up to go through the same proxy for all responses
Uri proxyURI = new Uri("proxy.dlsu.edu.ph:80");
GlobalProxySelection.Select = new WebProxy(proxyURI);
}
public static HttpWebRequest HwrAddProxy(HttpWebRequest httpRequest,
string proxyUri,
string proxyID,
string proxyPwd,
string proxyDomain)
{
if(httpRequest != null)
{
// create the proxy object
WebProxy proxyInfo = new WebProxy();
// add the address of the proxy server to use
proxyInfo.Address = new Uri(proxyUri);
// tell it to bypass the proxy server for local addresses
proxyInfo.BypassProxyOnLocal = true;
// add any credential information to present to the proxy server
proxyInfo.Credentials = new NetworkCredential(proxyID,
proxyPwd,
proxyDomain);
// assign the proxy information to the request
httpRequest.Proxy = proxyInfo;
}
// return the request
return httpRequest;
}
// for my server class
listener = new TcpListener(IpAddr[0],listenport);
Console.WriteLine(IpAddr[0].ToString());
listener.Start();
while (true)
{
try
{
Socket s = listener.AcceptSocket();
clientsocket = s;
clientservice = new Thread(new ThreadStart(ServiceClient));
clientservice.Start();
}
catch(Exception e)
{
Console.WriteLine(e.ToString() );
}
>
|
|
|
|
|
I would like to create a class that could be used to return values. I stored those values in a property so at times I will just retrieve it. My class looks like this:
Class1<br />
{<br />
private string _name;<br />
<br />
public Class1(){}<br />
<br />
public string Name<br />
{ get { return _name; }<br />
set { _name = value; }<br />
}<br />
}
My problem now, lies here: I would like to call those property in a way that "name" variable is an array-like? Meaning if i will use this class, I could have code like this:
Class1 c1 = new Class1();<br />
string name1 = c1.Name[0];<br />
string name2 = c1.Name[1];<br />
...<br />
...<br />
...
Could anyone tell me if it's possible to have a property which is array-like? If yes, how is it done? Thank you very much!!!
|
|
|
|
|
clasClass1
{
private string _name; //declare the string in array.
public Class1(){}
public string[] Name
{ get { return _name; }
set { _name = value; }
}
}
Hope this helps, I`m not sure how it`s done. Tell me if it works
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
A slight error in one line. It should look like:
<br />
private string[] _name;<br />
|
|
|
|
|
Maybe use an ArrayList (from namespace System.Collections) intead of strings...
using System.Collections
Class1
{
private ArrayList _name=new ArrayList();
public Class1(){}
public string Name
{
get { return _name; }
set { _name=value; }
}
}
in this way this code
Class1 myClass=new Class1();
Console.WriteLine(myClass.Name[0].ToString());
will write on screen the first object stored converted to string... In this way you can store different types of data (or objects), since ArrayList class is supposed to store "object" objects :P
Obviusly you need to know what kind of data you are going to retrieve from the ArrayList... ^^
|
|
|
|
|
that didn't work, i've tried it... thanks anyway
|
|
|
|
|
Why don't you try property indexers. For eg,
<br />
class Class1<br />
{<br />
StringArrayClass cs;<br />
<br />
public StringArrayClass Name<br />
{<br />
return cs;<br />
}<br />
<br />
<br />
class StringArrayClass<br />
{<br />
public string this[int index]<br />
{<br />
return array[index];<br />
}<br />
}<br />
|
|
|
|
|
Yes! that's exactly how i did it.. I look on a couple of samples in msdn.. thanks!!!
|
|
|
|
|
Hi All,
I am wanting to Add some nodes to a treeview. I have a main node and have added a node under it which is fine but I want to add another node under my second level node. How can I do this? At the moment my new node I am adding adds at the second level and not the third level.
A sample, if possible, would be appreciated. I am reading in the data from an array.
Thanks in advance.
Stephen
|
|
|
|
|
An example:
<br />
TreeNode firstLevel = new TreeNode("First");<br />
TreeNode secondLevel = new TreeNode("Second");<br />
TreeNode thirdLevel = new TreeNode("Third");<br />
<br />
treeview1.Nodes.Add(firstLevel);<br />
firstLevel.Nodes.Add(secondLevel);<br />
secondLevel.Nodes.Add(thirdLevel);<br />
|
|
|
|
|
Anybody know of a quick and easy way to get the value of a custom attribute on an enum?
e.g.
public enum Example
{
[Url("http://www.AURL.com/")]
AnEnum,
}
I can do it using about three lines of convoluted code but I was hoping there was a nicer way. ta.
regards,
Paul Watson
South Africa
The Code Project
Pope Pius II said
"The only prescription is more cowbell. "
|
|
|
|
|
Paul Watson wrote:
I can do it using about three lines of convoluted code but I was hoping there was a nicer way. ta.
No
I use the following normally:
foreach (UrlAttribute ub in obj.GetType().GetCustomAttributes(typeof(UrlAttribute)))
{
}
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
Dear Sir ,
I have a real problem when i deploy crystal report on any machine that only has .NET framework installed, but when the same project run on machine which has .NET installed it work proberly, i post Question before about the same issue and an expert send me link to MSDN to learn step-by-step how to deploy crystal report , and now after that all retries i have the same problem ..
When i run a progranm that has Crystal Report without making deployment it Generate "Commn language run time error" which an error i can't Understand it
at last i have a question : i want to be sure Which License Key must be provided to Properity of "Crystal_regwiz2003.msm" file :
C# .Net OR
Crystal Report for Visual Studio.Net
Sorry for my long Question
thank you ,
Shady Aly
|
|
|
|
|
I believe this needs to be the license key you get when you register the crystal reports.
|
|
|
|
|
Hi
I've used the article on making a compiler. It works and I can add assemblies ok eg. system.dll, but when I try to load microsoft.directx.dll which I put into the GAC myself it can't find it and I get an error C0006. I know the it is in the GAC and have checked that it is there. Whats wrong?
Thanks
|
|
|
|
|
|
Is there a way to prevent a program from throwing any exceptions at ALL to the windows operating system? Say I had a program that i wanted to run silently and never ever appear to the user.
Also, is there a way that I can have said program placed in a thread and killed at any time of my choosing? I am thinking specifically of some method from an object.
Thanks a lot,
Jim
|
|
|
|
|
Esmo2000 wrote:
Is there a way to prevent a program from throwing any exceptions at ALL to the windows operating system?
No. You can't control the execution of another application.
Esmo2000 wrote:
Also, is there a way that I can have said program placed in a thread and killed at any time of my choosing?
It creates it's own thread. You can't supply one for it. And, yes, you can kill the process at any time, but I don't recommend doing this. You run a much greater risk of destabilizing the system (more than it already is! )
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
And, yes, you can kill the process at any time, but I don't recommend doing this. You run a much greater risk of destabilizing the system (more than it already is! )
Now, I know what you mean and it is generally possible but I don't recall that I ever destabilized Windows (NT 4 and higher) by killing a process except for some cases where I was debugging some applications that used sub-classing (but in this case it was rather a bad API call than the process killing that destabilized the system).
Best regards
Dennis
|
|
|
|
|
If the process doesn't close nicely and it has unmanaged resources open, like most apps do anyway, those resources will suddenly find themselves orphaned. Kill enough apps like this and you'll evently run the system out of resources. Most of the time, if you do an End Process in Task Manager, the process will respond to the normal application shutdown messages. But if it doesn't, the process is then killed off using, shall we say, less than friendly methods.
Also, if the new process he launches launches other processes itself, those become orphaned.
It's just not a good programming practice...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
If the process doesn't close nicely and it has unmanaged resources open, like most apps do anyway, those resources will suddenly find themselves orphaned. Kill enough apps like this and you'll evently run the system out of resources.
You won't run out of resources in most cases. Any resource used by a process will be freed when a process terminates regardless of the reason for the termination, including the use of TerminateProcess()[^] (see Terminating a Process[^]).
Dave Kreskowiak wrote:
Also, if the new process he launches launches other processes itself, those become orphaned.
This is indeed one of the rare cases in which it would be a problem if the child processes don't exit on their own. However, if you really need to divide a solution in multiple processes the child processes should be able to handle the situation (the parent process might simply crash for example).
Dave Kreskowiak wrote:
It's just not a good programming practice.
I generally agree about that and definitely try to avoid it but if you want to automate a third-party tool (which could possibly be buggy), terminating the process might be the only possibility to handle certain situations.
Best regards
Dennis
|
|
|
|
|
Hello All,
please i need to know how can i put a checkbox in column in the datagrid control but with easy steps.in windows control not in webcontrol
please help
hay
|
|
|
|
|