101 vb.net Samples

bzbiz

Active member
Joined
Mar 17, 2003
Messages
34
Location
Emilia - Italy
Hi Folks!

Im very very new in .net world.

I use the 101 vb.net sample/VB.NET - Advanced .NET Framework (Networking) - Use Sockets, as core of my app.

All ok if i run the client and the server app in the same pc. But when i run the client from another one i catch a:

System.InvalidCastException.

Whats this???

Anyone know?

plz help.

ByeZ
By
BiZ
 
please give the section of code thats throwing this exception. Also check you datatypes look like your trying to covert for example a string to a integer or somthing on those line need the code though

Andy
 
hi, thanks for your reply.

I think that the problem is something about the system.net.socketpermission.

But i dont know how to use it.

ive tried somthing like this:

Try
client = New TcpClient()
permission.AddPermission(Net.NetworkAccess.Connect, Net.TransportType.All, "MyHost", System.Net.SocketPermission.AllPorts)
client.Connect("MyHost", PORT_NUM)
Catch Ex As System.InvalidCastException
MsgBox(Ex.Message, Ex.Source)
End Try
 
Solved!

it isnt a code problem, but a policy problem.

i used the configwizard of the .NET Framework to trust my app and now it works!

Thanks, for your time

ByeZ
BiZ
 
Hi, here the most complete answer i can:

NOTE 1: I talk about a win2000 professional.

Go to C:\WINNT\Microsoft.NET\Framework\ and look for configwizards.exe (change WINNT into Windows for 98/me/xp)

or

Control panel/admintools/microsoft.netwizards

NOTE 2: i have an italian OS so my translation may not match the english one.

Hope that help

ByeZ
BiZ
 
I have windows 2000 professional. So anyway i found the config wizard named "ConfigWizards.exe" But what do i do then:
-Trust an assembly (If so what do i set it to.)
-Adjust .net securty (what do i set the security to)

Ive tried alot of different combonations but still i havnt gotten it to work, just tell me what pereferences you set them to.
 
Hi,
ive done something like this:

ive selected to trust the assembly for the pc (not current user only), then ive setted the path of my app, then ive setted the trust level to the max, next, done!

This is the max trust way. you have to use it only with yours apps or with very secure apps otherwise "managed code", ".NET trust" etc etc became a nonsense

thats all folks

Hope that helps

ByeZ
BiZ
 
Ive been trying several things to make this networking chat thing better. I was trying to make it so that you could send an individual message to just one person on the server and not to everyone or an individual command. For example you type there name in a textbox, and then type the message in another text box, and hit a button. How do you think i could do this, i have tried alot of things to make it work, but continually get error messages.
 
Hi,

Im not sure but if you look at this:

[VB]
Private Sub SendToClients(ByVal strMessage As String, ByVal sender As UserConnection)
Dim client As UserConnection
Dim entry As DictionaryEntry

All entries in the clients Hashtable are UserConnection so it is possible
to assign it safely.
Try
For Each entry In clients
client = CType(entry.Value, UserConnection)

Exclude the sender.
If client.Name <> sender.Name Then
client.SendData(strMessage)
End If
Next
Catch ex As Exception
clients.Remove(client)
End Try
End Sub
[/VB]

Look around the "Exclude the sender" code. You can change it to send data only to the client you want, isntt it?

Ive abandoned the project months ago so i dont have much ideas about it sorry.

Always here for more help

ByeZ
By
BiZ
 
Going back to the trust things...

When you set the trust you get two options Set for Computer and Set for User. I am running a corporate network. If I create a program to be deployed on the network, can I set the trust for that program for the whole domain at once and not just Set for Computer or Set for User on each computer?
 
I was wondering if this project could go across a lan, and not just the internet. Is this possible?

Edit: I mean accross the internet and not just a lan.
 
Last edited by a moderator:
Hi,
im not a Networking master :cool: , but i think its possible.

The app listen on a open port, if this port is opened on the internet it can (i think) recive messages from it. You have to specify somewhere the IP of the server.

I think that security become a main problem in this case! Lots of more awarded instant messanger like ICQ, MSMessanger and so on, have some problem a selfmaded solution may be dangerous.

HTH

ByeZ
By
BiZ

P.S.
Probably ive written a lot of stupid things in this post sorry! :D
 
I think i got it to work over the internet now, but i havnt tested it yet, but im positive it will work. Im still trying to figure out how to do the exclude everyone except one person. I tried switching things around like this:
Code:
    Private Sub OneSend(ByVal strMessage As String, ByVal sender As UserConnection)
        Dim client As UserConnection
        Dim entry As DictionaryEntry

         All entries in the clients Hashtable are UserConnection so it is possible
         to assign it safely.
            For Each entry In clients
                client = CType(entry.Value, UserConnection)

                 Exclude the sender.
                If sender.Name <> client.Name Then
                    sender.SendData(strMessage)
                End If
            Next
    End Sub
But it still doesnt work, could someone plz help...

I also tried doing this:
Code:
 Private Sub OneUser()
        Dim sender as UserConnection
        sender = txtbroadcast.text
        sender.SendData("Chat|" & message)
        txtBroadcast.Text = ""
End Sub
When i try doing this, I get that txtbroadcast.text cannot be converted to UserConnect. What do you think is wrong with that?
 
Last edited by a moderator:
Could someone figure out how to get this to work? I have been trying for a few weeks now to get it work... This would be way easier to do if a string could be converted to userconnection. Is there anyway to do this?
 
Last edited by a moderator:
Back
Top