Results 1 to 19 of 19

Thread: changing over from vb6 to 2k5 winsock questions

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    changing over from vb6 to 2k5 winsock questions

    Hi everyone, this is my first post, figured i would start off by saying HI, and see if someone can guide me in the right direction. I'm coming into VB2005 from VB6 so im used to winsock controls, and i notice they arent there in vb2005 (.net) so im assuming theres another way we handle that... What i need to do is the following..

    1. Client app login attempt goes through winsock to server app.
    2. server app takes login information and checks it against database on server
    3. if credentials are good, then login make connection
    3a. im wanting to use the Username as the "winsock array index"
    4. if its not good login credentials send a message back to client app to stop right there and wait for better credentials.

    How can i go about doing this with 2005. in vb6 it was pretty easy but i was using 2 seperate servers 1 for login 1 for serverside, now everything is on 1 server. Thanks!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Welcome to the forums!

    Take a look at the TcpClient and TcpListener classes in the System.Net.Sockets namespace. Look at its methods and functions, play with them a little bit, read some about them on MSDN, read some about them on here. When youre done, do it once more, and you're pretty much good to go!
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    thanks for the welcome! ive played a bit and i see what you mean, i love it! now my next question...

    VB6 method was Winsock1(0).listen

    hence it becomes an array, and allows multiple connections, but VB6 angered me when i found out only 1 winsock control can listen on a form ( at least i was told this over and over and never was able to find out otherwise)

    VB2005.... will it automatically become an array or do i need to do anything special and if i have 1 form, can i have multple sockets listening at once? reason being my app, is going to transmit multiple types of data at once. could be text, could be video, could be audio, could be files, anything.. just alot of different types of data being transmitted... how does one go about doing this, would i be able to setup a Socket Array or something similar and have multiple arrays on a form? Thanks so much!

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Yeah you can declare as many TcpListeners as you want.

    VB Code:
    1. Public Class Form1
    2.     Dim listeners(9) As Net.Sockets.TcpListener
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim basePort As Integer = 44000
    5.         For i As Integer = 0 To 9
    6.             listeners(i) = New Net.Sockets.TcpListener(Net.IPAddress.Any, basePort + i)
    7.         Next
    8.     End Sub
    9. End Class
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Some additional information for you.

    You need to run a threaded loop in the background that constantly checks for connections. I have never done this with an array of TcpListeners but I suppose it should be the same, here you have an example:

    VB Code:
    1. Private Sub DoListen()
    2.         Dim client As Net.Sockets.TcpClient
    3.         Dim sr As IO.StreamReader
    4.         Do
    5.             For i As Integer = 0 To 9
    6.                 Try
    7.                     client = listeners(i).AcceptTcpClient
    8.                     sr = New IO.StreamReader(client.GetStream)
    9.                     MessageBox.Show("TcpListener " & i.ToString & " recieved the following:" & Environment.NewLine & sr.ReadToEnd)
    10.                 Catch
    11.  
    12.                 End Try
    13.             Next
    14.         Loop
    15.     End Sub

    Start this sub by calling it in a new thread at the end of form load.

    VB Code:
    1. Dim thrListen As New Threading.Thread(AddressOf DoListen)
    2.         thrListen.IsBackground = True
    3.         thrListen.Start()
    Last edited by Atheist; Nov 5th, 2007 at 05:00 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    absolutely awesome! this is much more powerful than VB6 was(is) also what about this..

    Client side have a TCP Listener that does the following...

    breaks down "indata" which can be something like (datatype|data) if datatype = 1 then its a message, if datatype = 2 then its a file transfer, and open a corrosponding tcplistener for it? this program will have alot of "messenger" features in it. similar to something like yahoo for example, instant messages are a big thing in this for contacting people

    any ideas on that one? and thanks again for being so helpful, im actually picking up on this pretty fast!

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Im currently doing a small network application project and I am basically using the same method that the socket example in MSDN 101 samples is using. Data are sent between the computers using strings, where the first part of the string tells the reciever basically what it is getting, and the rest of the string is additional info.
    So for example if the client sends this to the server:

    "MESSAGE|I do not own a snake game|Emil"

    The server recieves this string and breaks it down like this:

    'the strIncoming variable cointains the sent string

    VB Code:
    1. dim data() as string = Strings.Split(strIncoming, "|")
    2. ' The server splits the string on every | character
    3. Select Case data(0)
    4.    Case "MESSAGE"
    5.              MessageBox.Show("Message to " & data(2) & Environment.NewLine & data(1)
    6.    Case Else
    7.              MessageBox.Show("What the...is this?")
    8. End Case
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    Awesome! thas exactly what i needed to know!now i just need to put this into play in my app and see how it goes.. thats exactly what i needed though only my idea is datatype can be IM, FXfer, InCall, etc.. things like that so itll be more than one but i thnk were on the same page here. the Datatype tells it what to expect, data is the data, now heres another one for ya..... if 2 users are on a network, and connect through a router.... when the data is sent to the external IP....... itll go to both of them.. at least thats what i expereinced as an issue in vb6... im thinking of also putting in some extra info for it as well where it has the "TO" users name in there and if username = correct user show, otherwise ignore... am i gettin there thanks so much

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Ah I have never actually tried sending data it over the internet (yes I should be ashamed ) since all I ever have needed to do is LAN connections...I'll give it a thought though.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    yeah thats my big part is this is going to be over the net, if it was just intranet, i would be done already and would have stuck to vb6 lol but im going out on a limb here and trying to deploy it over the net. so its making things a bit more difficult. things i had issues with in vb6 were the simpler things like formatting text in a richtextbox but i was able to do multi user chat sessions.. go figure huh. how hard is the simple stuff in vb2005 now?

  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    The simple stuff is even simpler
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    i sure hope so, i got the 90 day trial from MS for VS2k5, got about 80 days left before i need to make a decision if im staying with it or not, but the more i play with it the more that 800 buck price tag doesnt look so bad!

    you have any suggestions on connecting to mysql from 2k5? itll be a local database, im wanting to client to send the server the info and the server to do all the processing ( thats what its there for right? )

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    also had another question for ya regarding this and since youre probably already doing this on the network i fugred id add it right in.... connection list.. you join a chatroom you can see whos in there, in VB6 i had nothing but headaches... what control would be best? treeview ( i tried in vb6) or listview ( never was any good at these for some reason) i want it to be interactive where they can right click etc... and all that jazz, right click to open small box to send message, get profile etc.. Thanks again so much

  14. #14
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Personally I use the ListView for the online list, nice to be able to have columns and icons by the names.

    The MySQL thing..I dont know really...havnt touched mysql much at all...

    You can download the VB 2005 Express Edition from microsoft for no cost at all Its simpler than Visual Studio 2005 but Im using it (lack of money) and I havnt yet found anything I miss in it. Its amazingly good for being free. You should try it first, if its no good for you, then buy the full kit
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    have you tried the 90 day trial vs the express edition? i know the express cant do remote database but im guessing if the database is on the local machine it should be jsut fine. and if i go with a listview, do you think you can give me a few pointers? im using a treeview for the "buddy lsit" so i can do the "Online" and "offline" contacts, but yeah for the room list i think a listview should suffice no need for a tree really Thanks so much youve been very very helpful. and ive rated the post and wil continue to do so, thanks so much!

  16. #16
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    Nope Ive never tried the 90 day version of visual studio...perhaps I'll check it out someday

    Yeah sure I can tell you whatever youd want to know about the ListView hehe Check this ListView control overview
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  17. #17

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    very cool info on the list view, so basically i could put 3 columns, 1 for a small camera icon, 1 for a small mic/no mic icon and 1 for the username. and then make the username column right clickable to open a small box to pick options (send IM, profile etc) and double click the name to open IM box..... no problems with any of that?

  18. #18
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: changing over from vb6 to 2k5 winsock questions

    No problems at all as far as I can see
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  19. #19

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    43

    Re: changing over from vb6 to 2k5 winsock questions

    added listview to the form, now, the fun stuff..which most of it i already figured out with vb2005, this is so much easier than 6. what im curious about now is this.... do you already have something like this working and if so whats the best way for me to start, i want to setup my first socket control on the client side. where its ready to accept incoming stuff..... BUT im thinking.... if i setup a socket control on the login box, can i close it out or should i keep that one active until program shut down, will that track users more accuratly? as to what room they are in, if they are connected etc.... can you help me get the initial stuff setup and let me go from there with it? i mean login box, can you help me get it setup where it will connect to my server app, setup server app to listen and on successful login add the name to either the index, or a list or something where it will keep track of offline/online users? that would be so awesome! Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width