|
yes i can ping
i think problem is firewall or windows security
when i run that first appear windows security unblack window
|
|
|
|
|
Hi
I am sending the ip address and the port no for the socket using the following syntax:
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8050);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep); Because of the connection problem i want to read both the ip address and the port no from an xml file.I do not exactly know how i should be storing data in an xml...In the xml file named p1.xml i have given the following:Please check whether this is right and give me your suggestions
<table width="100%" border="0">
<tr>
<td><address>127.0.0.1<address>
<td>
<tr>
<tr><td>
<port>10001<port>
<td><tr>
I am using the following code for reading the data from the xml file:
XmlTextreader reader = new XmlTextReader("p1.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text:
String s=reader.Value;
}
} My doubt is that will the string variable "s" take values of the ip and port..and how do i fit it into the socket statement...please help me with this
|
|
|
|
|
That is not XML.
How about:
<endpoint>
<ip>127.0.0.1</ip>
<port>43211</port>
</endpoint>
And please use a better way to read the XML..
Last modified: after originally posted -- darned angle brackets
|
|
|
|
|
Hi
Both the values of port and ip are integers.
I am able to read all the text values from the xml
I am using
XmlReader re=new XmlReader("p1.xml");
String s=re.Value;
this returns all the text values stored in xml.But i want to retrieve both the port and ip and assign to 2 different integer variables.I am not sure of this..Please help me with this
|
|
|
|
|
Hi
I tried with the following code.There is no error at the compilation time but something goes wrong at the run time.I do not know how to retrieve the ip and port from the xml..Please help me with this
public static void start_server()
{
XmlTextReader r1 = new XmlTextReader("p1.xml");
XmlDocument doc1 = new XmlDocument();
doc1.Load(r1);
int ipadd = r1.ReadElementContentAsInt();
int ports = r1.ReadElementContentAsInt();
IPEndPoint ipep = new IPEndPoint(ipadd, ports);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
Console.WriteLine("Waiting for a client...");
while (true)
{
try
{
byte[] data = new byte[1024];
Console.WriteLine("hai");
int recv = newsock.ReceiveFrom(data, 0, data.Length, SocketFlags.None, ref tmpRemote);
Console.WriteLine("gfgjfk");
Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[1024];
string ss = "Welcome to the Server";
data = Encoding.ASCII.GetBytes(ss);
newsock.SendTo(data, 0, data.Length, SocketFlags.None, tmpRemote);
Console.WriteLine("\nSent Acknowledgement");
}
catch (SocketException e)
{
Console.WriteLine(e.Message);
}
}
}
|
|
|
|
|
You aren't correctly specifying which element to read. Try the XPath trick I mentioned earlier, it should always work (provided, of course, that your XPath matches your actual XML)
|
|
|
|
|
Hi
I retrieved port and ip using
for (int i = 0; i < xmlnode.Count; i++)
{
st = xmlnode[i].FirstChild.InnerText;
st1 = xmlnode[i].LastChild.InnerText;
}
ipadd = Convert.ToInt32(st);
ports = Convert.ToInt32(st1);
IPEndPoint ipep = new IPEndPoint(ipadd, ports);
It gives me an exception"Input String was not in a correct format" but the server(.exe) opens up.In the server code i have used
IPEndPoint ipep = new IPEndPoint(ipadd, ports); to open the connection with the client.For this opened server how should i change the following statement on the client
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10001);
How should i specify the port and ip on the client?i.e for the server opened on port 10001 and ip=127.0.0.1 (obtained from xml) how should i modify the client?Please give me your suggestions
|
|
|
|
|
Ok debug your code, put a breakpoint on "ipadd = Convert.ToInt32(st);" and watch the value of st and stl. You may be in for a surprise.
To solve this problem.. just start using SelectSingle on an XmlDocument. It's at least 10 times as easy to get right.
As to specifying the ip/port in the client - the exact same way you did it in the server will do fine.
|
|
|
|
|
your using HTML... look for an XML primer
|
|
|
|
|
i am reading datas in text file and write into another text file..but getting exception ...
FileStream fs=new FileStream("C:\\Vicky\\DATAS\\1.txt",FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
FileStream fs1 = new FileStream("c:\\one.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs1);
string[] s = new string[500];
for(int i = 0; i <= 500; i++)
{
s[i] = sr.ReadLine();
}
for (int j = 0; j <= 500; j++)
{
sw.WriteLine(s[j]);
}
sw.Close();
sr.Close();
fs.Close();
fs1.Close();
error is:
Index was outside the bounds of the array.in s[i]=sr.readline().....
|
|
|
|
|
An array is 0 based, so 500 elements are indexed from 0 to 499.
Just get rid of the = in the for cycles
|
|
|
|
|
thanks man....we got it.....can u explain me wat problem we did it ....explain it briefly.
|
|
|
|
|
An array is 0 based. So if the array contains 500 elements the first has index 0 and the last 499. In your for cycle (with <=) at the end you were trying to access to the element with index 500 that obviously is outside the bounds of the array.
http://msdn.microsoft.com/en-us/library/9b9dty7d(VS.80).aspx[^]
|
|
|
|
|
nettai wrote: explain it briefly.
You did it wrong.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
[0,499].Contains(500)==false
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
sorry man I'll try harder next time plz urgt
|
|
|
|
|
Hi All,
i'm trying to connect to the Deleted objects container in AD by using:
DirectoryEntry de = new DirectoryEntry("LDAP://CN=Deleted Objects,DC=domain,DC=com")
and it is retuning with an error saying - There is no such object on the sever. but i can see it when i use LDP!!
can anyone help?
Many Thanks,
phil
|
|
|
|
|
hi
i want to make a database in sql server 2000 using c# withoust using sql server enterprise manager, how it will be done? please help me i have searched alot but unable to find enough information
|
|
|
|
|
|
|
there is this thing called a book... In it they have examples and tell you how to do things. Plus if you want to make life hard for yourself with out using enterprise manager you should be able to do this yourself!
|
|
|
|
|
hi from where i can get that book, and there is a restriction cant use enterprise manager
|
|
|
|
|
Hello gurus,
I have a simple question for C# masters concerning controls.
I have a series of label with a formated name.
In a loop, I want to recover a pointer on the control (a label) by giving its name as a string.
for example:
<br />
Label lbl = null;<br />
string lblName = "";<br />
<br />
for (int i=0; i<5; i++)<br />
{<br />
lblName = "lblL" + i.ToString();
<br />
lbl = ???;
<br />
<br />
lbl.Text = i.ToString();<br />
}<br />
<br />
How to make the control pointing to the right one given its name?
I hope you understood my question in my poor english.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
Hi Fred,
Would the following solve your problem:
lbl = new Label();
lbl = (Label)FindControl("lblName");
Ryan
|
|
|
|
|
Yes, that's it, in a recursive way and for WinForms.
There is no spoon.
modified on Thursday, March 12, 2009 10:41 AM
|
|
|
|