|
Dim listener As New TcpListener(System.Net.IPAddress.Any, 7778)
'start it
listener.Start()
Dim bytes(1024) As Byte
Dim Command As String = Nothing
While True
Console.WriteLine("Waiting for a connection... ")
Dim client As TcpClient = listner.AcceptTcpClient()
Console.WriteLine("Client connected... ")
Console.WriteLine("Please Wait... ")
Dim ns As NetworkStream = client.GetStream()
Command = Nothing
Dim i As Integer
i = ns.Read(bytes, 0, bytes.Length)
While (i <> 0)
Command = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
Console.WriteLine(Command)
i = ns.Read(bytes, 0, bytes.Length) 'stopper
End While
ns.Close()
client.Close()
Console.WriteLine("...")
End While
Can anyone please help me why the execution stops at the bold line. Compiler don't execute anything after this line?
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
When you say stops, do you mean it throws an exception? What is the exception?
have you looked at the networkstream class documentation, you should be testing it canread before trying to read. look at the read method docs.
[modified text]
i just noticied that you have basically copied the example in the MSDN for the TCPListener, i have found in the past that these are not always reliable, and basically just show how everything hooks together, you still then need to look at each of the classes you are using to get more of the specific requirements (like the canread etc.)
modified on Saturday, January 30, 2010 3:34 AM
|
|
|
|
|
Thank you for your reply daveauld. Actually it didn't throw any exception at all just stops the execution and won't continue the loop or the remaining statements after the loop which is kind of weird. Do you have any idea what's wrong with the above code???
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
I would change the read part to match the example in the networkstream.read example in the docs so;
Do
numberOfBytesRead = myNetworkStream.Read(myReadBuffer, 0, myReadBuffer.Length)
Loop While myNetworkStream.DataAvailable
|
|
|
|
|
Hi,
Stream.Read() is a blocking call. Read the documentation, it contains:
"read; however, if an exception occurs, the current position within the stream remains unchanged. Implementations return the number of bytes read. The return value is zero only if the position is currently at the end of the stream. The implementation will block until at least one byte of data can be read, in the event that no data is available. Read returns 0 only when there is no more data in the stream and no more is expected (such as a closed socket or end of file)."
So your program is waiting inside the Read() method for more data to become available. You may have to restructure your communication, maybe use asyncrhonous calls, another thread, a time-out, it all depends on the circumstances.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
It stops because .Read is a blocking call and won't return until it has actually read something. Since there's nothing more to read, the .Read call will sit there until there is something.
|
|
|
|
|
Thanks for your answers guys now i got the reason for this kind of behavior.
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
Hi All.
I'm new to vb and hope you can help me. I want to create a pc audit database program.
I've got two forms:
Form1 displays in a gridview with three tables and
Form2 displays in details view with all the data.
I want the user to select a row in the gridview and click a button that will open form2 and display all the info of that pc.
Any help will be appreciated.
Thank you.
|
|
|
|
|
In Your project you need to create a class for PC. In form2 you need to create a property (i.e. CurrentPC) that returns a PC object. In the constructor for form2 you need to include a parameter that accepts a PC object. When the user clicks on the datagridview you can create a new form2 passing on the specific PC object. Good luck
|
|
|
|
|
Thanx for your help but I've got no idea what that means.
Like I said, I'm new to VB. Could you explain that please.
Thank you.
|
|
|
|
|
Why don't you let me know what you have attempted to do yourself and then we can work from there. Really, you should know a little bit more of the basics before attempting such a project, at least enough to have actually followed what I posted before.
|
|
|
|
|
My database name is "DBASE"
I had a look at the DBASEBindingSource properties of Form1 and saw that the DataSource is set to "Form1 List Instances - PC_auditDataSet" and on Form2 it's set to "Form1 List Instances - PC_auditDataSet"
I was thinking that if I can someway set both to be the same that if I select something in form1 that the same thing would be selected in form2.
That didn't work so I was thinking of coding a variable to say that if a row number was selected in the datagrid that the same number would be displayed in the list view on form2.
So basically I need help with the variable (if it can be done that way)
|
|
|
|
|
As far as I can tell, you basically want form2 to display the information of a particular PC, depending on the row clicked by the user in the DataGridView in form1. Have a look at the code below for form1 and form2 as I would implement this.
Public Class PC
Private intID As Integer
Private strName As String
Public Sub New()
End Sub
Public Sub New(ByVal PCID As Integer)
ID = PCID
Name = "PC " & PCID
End Sub
Public Property Name() As String
Get
Return strName
End Get
Set(ByVal value As String)
strName = value
End Set
End Property
Public Property ID() As Integer
Get
Return intID
End Get
Set(ByVal value As Integer)
intID = value
End Set
End Property
End Class
Public Class Form1
Private lstPC As New List(Of PC)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Create some simple PC's for example purposes
For i As Integer = 1 To 5
Dim newPC As New PC
newPC.ID = i
newPC.Name = "PC " & i
lstPC.Add(newPC)
Next
DataGridView1.DataSource = lstPC
End Sub
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
Dim newForm2 As New Form2(lstPC(e.RowIndex))
newForm2.Show()
End Sub
End Class
Public Class Form2
Private pcCurrent As Form1.PC
Public Sub New(ByVal newPC As Form1.PC)
InitializeComponent()
pcCurrent = newPC
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView1.Items.Add(pcCurrent.Name)
End Sub
End Class
To run this, you need to have Form1 with a DataGridView named DataGridView1, and a second form Form2 with a ListView (ListView1). For this example I created a simple PC class, and just pass the particular PC object to form2 via form2's constructor. There are various ways of doing this, i.e creating a public property in form2 that returns a PC object, and then when declaring your new form2 you set the property to the specific PC object your user wanted. Hope this helps.
|
|
|
|
|
Hello everybody,
I want to make a little helper program to set up panels for MS Flight Simulator. Basically the panels use a background bitmap is overlayed with re-usable gauges, which I therefore don't have to program. These gauges seem to be more or less dll files (extension *.gau) or xml files organized in cabs.
Unfortunately I have no idea how to access the properties and methods of the *.gau files and how to integrate them into a VB.NET program. VB.NET doesn't let me set a reference to the gau file, and it also doesn't help to just change the extension to *.dll ("... not a valid file..." etc.).
Could someone please give me a few hints how to start that?
Thank you
Michael
|
|
|
|
|
MS Flight Simulator SDK SP1a[^]
Other than that, you're best source of information is going to be sights dedicated to Flight Simulator developement. It's extremely unlikely you'll find anyone here with that kind of experience you need.
|
|
|
|
|
Thank you, Dave.
I was hoping there'd be some general method in .net how I could explore what such a file exposes. Too sad... the whole FS stuff is in C++ and therefore some even more alien world for me.
Thanks still
Mick
|
|
|
|
|
Michael Schäuble wrote: I was hoping there'd be some general method in .net how I could explore what such a file exposes.
Files tend not to expose anything, but are (mainly) just a stream of bytes, written in a predetermined order. The only way, generally, to access the content is to get a document that describes their format. Occasionally it is possible to figure it out by using a hexdump of their content but with more complex files that is becoming more difficult.
MVP 2010 - are they mad?
|
|
|
|
|
I have a (Zed) graph with a Y Axis and a Y2 Axis, but the major amd minor ticks come at difference spacings leaving a ragged axis with the two jumbled up on both sides.
Is it possible to turn off the repeat of the Y Axis ticks on the Y2 Axis and vice versa. I have tried everything I can think of to try and get the spacings the same, but fix one and another dataset breaks it. I can't see a setting that is recognisable to me for doing this.
It is not a problem if the scale of the two axis is different.
|
|
|
|
|
Hi,
I have developed a class library to be used in a Windows project as well as a web project. Because I am developing plugins for a 3rd party CMS, the web project requires me to add some references to the class library so that I can comunicate with the CMS from my plugins. The back office Windows application, however, doesn't have the referenced CMS files available so the application fails.
Do I need to copy all the referenced files to each machine where I want to use the class library, even though the Windows app doesn't require them (none of the class library procedures called from the Windows app uses the referenced CMS files). Or is there some way I can exclude them when compiling the class library for the Windows App?
Thanks for your time.
|
|
|
|
|
If the Windows app does not use the portion of the common library that interacts with the CMS system, I would move the portion that does interact with the CMS into another library. Then you would end up with something like the following:
Windows app --> common library <-- Web project --> CMS plugin
|
|
|
|
|
OK Gideon that's great, thanks for your time and advice
|
|
|
|
|
Experts i have mostly figured out the code i need howevr am slightly stuck!
I have a database which works fine, i want to delete a record that i have highlighted,
code :
dim lbk as long
lbk = Adodc2.recordset.bookmark
Adodc2.refresh
Adodc2.recordset.move lbk
Adodc2.recordet.delete
This code will delete the last record and not the record selected
Im sure that there is something little in this code which isn't working, if anybody can help that would be great
Cheers
Dan
|
|
|
|
|
offroaderdan wrote: Adodc2.recordset.move lbk
should be :
Adodc2.recordset.bookmark = lbk
Are you sure the type of lbk is long ?
|
|
|
|
|
Thanks for that. However it comes up with run time error 3001, in conflict....
ummm just so i read your post write the code should go
dim lbk as long
lbk = Adodc2.Recordset.bookmark ' same as below
Adodc2.refresh
Adodc2.recordset.bookmark = lbk ' this is near enough repeated
adodc2.recordset.delete
Thanks again for the reply
and yeah i am sure that lbk is long as it will delete a record but not the one i want!
|
|
|
|
|
I seem to remember that the Bookmark property is a variant
|
|
|
|