|
solved
i will use that axbrowser intead, i add to tools
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hello guys!
I'm writing my first network based application in order to learn yet a little more about the C# programming language. And I've been up for hours now working on this program that works, to about 99%. But I want this extra feature that helps me when beta testing it. It's a server / client application that simply connects using sockets and IP addresses. I found it to be the best starting point since it's really basic.
So, the problem I have is that I made a "preloader" for my program, when the server starts it directly tries to establish a connection to my IP in order to send the servers IP address to me. If I got my client up and running and I've choosen to scan for new connections then it works as intended. However, I only get 1 IP adress, the first line sent to me. I know why, I just dont know the best solution to get multiple lines recieved.
Posting a small example so that you guys might be able to help me out on this one.
private void b3_Click(object sender, EventArgs e)
{
try
{
string serverIP = "";
TcpListener tcpListener2 = new TcpListener(1235);
tcpListener2.Start();
Socket socketfromServer = tcpListener2.AcceptSocket();
networkStream2 = new NetworkStream(socketfromServer);
streamReader2 = new StreamReader(networkStream2);
streamWriter2 = new StreamWriter(networkStream2);
serverIP = streamReader2.ReadLine();
t3.Text = serverIP;
}
catch (Exception xx)
{
MessageBox.Show(xx.ToString());
}
}
The server uses a For loop and if more IP addresses then one are found, then it will use WriteLine to post them one after another until they are all sent. With this usage, I got 1x ReadLine(), and thus I only get the first line sent from the server. So, how do I get multiple lines in a smart way? ^^
|
|
|
|
|
noiser wrote: serverIP = streamReader2.ReadLine();
Will only ever read one line ya know!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Yes, I know. That's why I'm wondering what other function to use or how use the readline to get multiple lines of data.
|
|
|
|
|
how about:
string line;
while((line = streamRead.ReadLine()) != null)
{
// do something
}
or
string text = streamReader.ReadToEnd()
However all those method have problem when reading from a socket where the flow of data is potentially unpredictable (although, I believe, a TCP packet is at least 255 user bytes long and guaranteed to arrive in one burst)
So it's why over the wire communication protocol makes heavy use of header fields!
I would be you, the simplest thing I would do is
// server
var br = new BinaryWriter(outsream);
br.Write(numString);
for(int i=0; i<numstring; i++)="" br.write(strings[i]);
on="" the="" server="" side
var="" br="new" binaryreader(instream);
int="" n="br.ReadInt32();
for(int" i="0;" i<n;="" list.add(br.readstring());
and="" that's="" simplest="" one!
i="" might="" do="" some="" more="" sophisticated="" header...
and="" better="" exception="" handing="" of="" course!="" =""
<div="" class="ForumSig">A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Ey thanks man! This is a much better answear then the first one.
I'll be trying these methods out.
|
|
|
|
|
Cool!
Good luck with that!
Yeah, sometimes I feel cheeky with questions and answers...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I fixed the problem. ^^
Using this code block dosn't work. Apparently it gets stuck on reading the last line even though it should be empty.
string line;
while((line = streamRead.ReadLine()) != null)
{
}
So what I did was this:
while ((serverIP = streamReader.ReadLine()) != "EOF")
{
ipBuffer += serverIP + "\n";
serverIP = "";
}
On my server application whenever I am done sending data I send a line with the text "EOF" and thus I can break the infinite loop. :P
|
|
|
|
|
Hello,
VS 2008 SP1
I am using the web client to download a file. Which works ok.
However, now I have to download many, and the number of files to download will change everyday. And will not know the name of the files.
I am not sure how I can get the web client to know which files have been downloaded or not? I was thinking of using a for loop to download each file. But I will never know how many there are to download?
The web client could download the same file twice?
Many thanks for any suggestions,
private void btnStartDownload_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("SomeURLToFile"), "SomePlaceOnLocalHardDrive");
btnStartDownload.Text = "Download In Process";
btnStartDownload.Enabled = false;
}
|
|
|
|
|
Why would it download the same file twice ? Why would it miss a file ? Where does the list come from ? How do you hope to work out what you want ?
You can work out what's been downloaded by checking if a file exists. That won't help you if the file needs to be downloaded again. You could keep a list in memory of files downloaded today and compare to your download list
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Trying to Fill
List string Items = new List string();
with textBox1.Text.
Anyone help me out on how to do this, or point me to where I can Learn how?
I want the code to read textBox1.Text until endofline add word to List then go to the next until the end.
|
|
|
|
|
You can use the split method on the string class to break the text in the textbox into lines, then you will have a string array to work with.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I am using a data grid view which loads data from the database and displays. Moreover, on my form are the buttons as INSERT(i.e for inserting records in database and grid), DELETE_SELECTED_ROWS(i.e for deleting records from database and grid). Now as you know that grids are editable so if any changes are made inside the grid then how to update.
Talking all in all I need to know how to update a dataset/datatable
<pre>
<code>
private void ManageCustomer_Load(object sender, EventArgs e)
{
LoadCustomers();
}
private void btnInsertInDataBase_Click(object sender, EventArgs e)
{
// Insert Customer In Database
DALHelper helper = new DALHelper();
helper.InsertCustomer(textBox1.Text);
LoadCustomers();
}
private void LoadCustomers()
{
// Load Cashiers from Database
DALHelper dal = new DALHelper();
dataGridView1.DataSource = dal.GetCustomers();
dataGridView1.Refresh();
}
List<int>customerIDsToDelete = new List<int>();
private void btnDELETE_Click(object sender, EventArgs e)
{
// Iterate all the Rows in DataGridView Rows Collection
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// Get the status of CheckBox in the current Row
bool deleteStatus = Convert.ToBoolean(row.Cells[0].Value);
// Get the CashierID of the Cashier in the current row
int customerID = Convert.ToInt32(row.Cells[1].Value);
if (deleteStatus)
{
row.Selected = true;
customerIDsToDelete.Add(customerID);
}
}
// Remove From DataGridView
foreach (DataGridViewRow selectedRow in dataGridView1.SelectedRows)
{
dataGridView1.Rows.Remove(selectedRow);
}
// Remove From Database
DALHelper dal = new DALHelper();
dal.DeleteCustomers(customerIDsToDelete);
customerIDsToDelete.Clear();
// Load Cashiers from Database
LoadCustomers();
}
}
}
// THE FOLLOWING IS THE CODE I AM USING IN MY DAL(Data Access Layer) CLASS
public DataTable GetCustomers()
{
string query = "SELECT * FROM Customer_2";
SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();
da.Fill(table);
return table;
}
// For Inserting Customers
public void InsertCustomer(string customerName)
{
string query = "INSERT INTO Customer_2 (CustomerName) VALUES (@CustomerName)";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = customerName;
con.Open();
com.ExecuteNonQuery();
con.Close();
}
// For Deleting Customers
public void DeleteCustomers(List<int> customerIDsToDelete)
{
string query = "DELETE FROM Customer_2 WHERE CustomerID = @CustomerID";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
SqlTransaction tr = null;
try
{
con.Open();
tr = con.BeginTransaction();
com.Transaction = tr;
com.Parameters.Add("@CustomerID", SqlDbType.Int);
foreach (int item in customerIDsToDelete)
{
com.Parameters["@CustomerID"].Value = item;
com.ExecuteNonQuery();
}
tr.Commit();
}
catch (Exception ex)
{
tr.Rollback();
throw ex;
}
finally
{
con.Close();
}
}
</code><code></code><code></code></pre>
|
|
|
|
|
"...Now as you know that grids are editable so if any changes are made inside the grid then how to update..."
sorry i didn´t check your code because of this sentence
you don´t edit that DataGridView, you edit the database
in sql database, you create Store Procedures that you trigger in an c# event like button click
the SP you create are: insert row, update row, delete row etc etc etc
so, to make changes in the DB you have to trigger the procedure you want, after, show it in the DGV
(later, don´t forget to use crystal report to display and print data)
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
I have a web service (Called ABWebService) that I have created that contacts someone else's webservice (ZWebService). My main project has a reference to ABWebService and also has a reference to ZWebService, which it needs to contact directly. The problem I have is if I create a WebMethod in ABWebService that gets passed an object from ZWebService in the web method it is expecting and object of type ZWebService. But in the Main Project if I call the web method in ABWebService the object type for what I am passing is ABWebService.object, even though the type of object I want to pass to it is ZWebService.object.
It then says I can't do this because they are different types.
Any suggestions?
|
|
|
|
|
Your issue is not coming out very clear.
|
|
|
|
|
how do i import
this reference is not availbale in device application
any way to solve???
pls help................
This code was posted by me...
|
|
|
|
|
It won't work because none of the Deployment classes are supported by the .NET Compact Framework used by devices.
You're only recourse is to either find a 3rd party library that offer equivilient functionality (I don't know of any) or make your own from scratch.
|
|
|
|
|
why not you use Reflection to load the assembly ??
Also mind that, you can only call Deployment dlls from Compact framework.
|
|
|
|
|
reefleciton??
what is taht
pls explain
This code was posted by me...
|
|
|
|
|
you dont know about Reflection classes ?
Even .NET itself reads everything using Reflection, when you take reference to a dll.
System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFile("Path");
Read basics of System.Reflection classes to get the idea. Its very simple.
|
|
|
|
|
I'm trying to make my program take a screenshot of a webbrowser after it finishes navigating and all I seem to be able to do is take a screenshot of it before it finishes navigating (a white rectangle). It's probably something very simple that I just keep missing, but am getting too annoyed to see it.
I stepped through it and apparently it takes the screenshot when the webBrowserForScreenShot is called after Navigate has been called, but no image is present. However the url is set for the webbrowser to the address it was sent by navigate. I also tried a while loop until webBrowser.ReadyState = complete, but ended up in an infinite loop. I tried adding Application.DoEvents(); as the action in the loop and then end up with a black rectangle. Btw, it does load the page after all is said and done, just too late to be a part of the screenshot. Any help would be great!
public ScreenShotWin()
{
InitializeComponent();
openWebBrowser();
}
public void openWebBrowser()
{
webBrowser1.Navigate("http://google.com");
}
private void webBrowserForScreenShot(object sender, WebBrowserDocumentCompletedEventArgs e)
{
IntPtr htmlWindow = webBrowser1.Handle;
CaptureWindowToFile(htmlWindow, "C:\\Interbank.bmp", ImageFormat.Bmp);
}
this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowserForScreenShot);
|
|
|
|
|
This is because a DocumentComplete event fires once for every frame in the WebBrowser. However, the second event argument has a Url property. If e.Url == webBrowser1.Url , then the control has finished loading the top-level frame; this is usually the browser window.
I got some of this from MSDN forums, here. If the == operator doesn't work, you could also try the Equals method
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Actually, the URLs matching is another one of fun parts. When it finishes navigating, the URLs match, the page is still not loaded.
It turned out to be a threading issue. I created a timer after my webbrowser navigated and checked per every 1000 ticks if the readystate was equal to complete. Very annoying, but it works now. A lesson well learned about trusting documentation.
Thank you for your help.
|
|
|
|
|
Hello,
VS 2008 SP1
I have created a application that I have installed on the user computer. However, I want the application to be self-updating. But I am not sure if this would really update the application.
The application will download all the files from the web server, and replace the files in the directory where the program as been installed to. The user will restart the application.
I am just want to be sure, because I can't replace the installed files with the updated ones. As the application will be running. So really the application cannot delete/replace itself.
So, I was thinking that I could download into another directory, if the program is installed in this directory 'program files/application/1.0.0' then I could download the files to 'program files/application/1.0.1'.
However, when the program restarts, how can it know that it has to execute from the 1.0.1 directory?
I can't use clickonce or the updater block for this.
Many thanks for any advice,
|
|
|
|