Page 2 of 2 FirstFirst 12
Results 41 to 62 of 62

Thread: [Guide] Winsock - Chat Application

  1. #41
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [Guide] Winsock - Chat Application

    When a client disconnects I normally unload the Winsock control that is associated with that client
    VB Code:
    1. Private Sub Winsock_Close(Index As Integer)
    2.     Unload Winsock(Index)
    3. End Sub

  2. #42
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: [Guide] Winsock - Chat Application

    Isn't it better if you leave it as it is, but just close the connection ? That way you can use it later on, for a new connection... (that's what I always do)
    Also... I think it's weird to have a gap in the control array...

  3. #43
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [Guide] Winsock - Chat Application

    Also... I think it's weird to have a gap in the control array...
    So do I, hence my previous bit of code.
    Poor Pino, we're ruining his nice thread.

  4. #44
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: [Guide] Winsock - Chat Application

    I mean like this:

    This code is from the server I made for work, wich we use for more than a year now...
    VB Code:
    1. Private Sub SckTCP_Close(Index As Integer)
    2.     CClients = CClients - 1
    3.     SckTCP(Index).Close
    4.     ClearUser Index
    5.    
    6.     If Index = 0 Then
    7.         ConnectAllSockets
    8.     End If
    9. End Sub
    10.  
    11. Private Sub SckTCP_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    12.     Dim K As Integer, SHA As New clsSHA256, StrToSend As String
    13.    
    14.     For K = 1 To SckTCP.UBound
    15.         If SckTCP(K).State = sckClosed Then Exit For
    16.     Next K
    17.    
    18.     If K = SckTCP.UBound + 1 Then
    19.         Load SckTCP(SckTCP.UBound + 1)
    20.         Load tmrSendData(SckTCP.UBound)
    21.        
    22.         ReDim Preserve Clients(SckTCP.UBound)
    23.        
    24.         K = SckTCP.UBound
    25.     End If
    26.    
    27.     Randomize
    28.     Clients(K).State = 0
    29.     Clients(K).CLogIn.RndINIT = UCase(SHA.SHA256(CStr((2 ^ 30) * Rnd)))
    30.    
    31.     SckTCP(K).Accept requestID
    32.    
    33.     StrToSend = "RndINIT|" & Clients(K).CLogIn.RndINIT
    34.     SckTCP(K).SendData Len(StrToSend) & ":" & StrToSend
    35.    
    36.     CClients = CClients + 1
    37. End Sub

  5. #45
    New Member
    Join Date
    Oct 2005
    Posts
    11

    Re: [Guide] Winsock - Chat Application

    Quote Originally Posted by Pino
    Ok Ladies gents, and frogs, i have edited the guide slightly and included the source code now, I hope people find this usefull

    I have included it in the format of a word document with the source code all zipped up together,

    PINO-

    This is a very good tutorial but you forgot to include some stuff (which the most BEGINNER programmers wouldnt know how to do)

    in the parts where you say stuff like

    "ok so now your server is listening we must handle connection requests, this is when the client try’s to connect to us!



    Private Sub Winsock_ConnectionRequest(byVal RequestID as long)"

    you didnt include the part that tells HOW to get the above statement (the sub_winsock_connectionrequest) event...so that may be a tad bit confusing (of course I kno how to get it cuz this is my 2nd year of programming)...you also didnt mention that you have to double click the form and select the LOAD property to enter the first bit of code you give

    sorry for the negative feedback...just think of it as constructive criticism

    thanks for the tutorial...hopefully i wont have any questions but if i do i will let you know...and maybe we can write another tutorial together

  6. #46

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [Guide] Winsock - Chat Application

    Thanks for your comments,

    I think if somone is beginning to learn winsock then they should know a decent level of programming, and stuff like getting the correct subs well i'd assume they would know that.

    Thanks for the feedback though, either way the guide has helped several people get to grips wihth winsock thats all it was here for not supposed to be a full explination

  7. #47
    New Member
    Join Date
    Oct 2005
    Posts
    11

    Re: [Guide] Winsock - Chat Application

    your welcome for the comments, again I am sorry they sounded so negative....

    i attempted to use it to learn winsock...but its just wayyy over my head...

    normally when you learn a new command u learn the generic use of it correct? such as the command button....when I learned it all we first learned to do was make a pic visible..so thats simple....winsock is just....CONFUSING!

    thanks for taking the time out to write the guide regardless...and i hope you have fun in the future with whatever helpful projects you make work on

  8. #48

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [Guide] Winsock - Chat Application

    Well in all honesty this is the simplest format of how winsock works, if this above you I feel you are not ready. Also this is old now move to .NET :-D

  9. #49
    New Member
    Join Date
    Feb 2006
    Location
    Karachi
    Posts
    5

    Re: [Guide] Winsock - Chat Application

    Thanks
    Because this codes helped me very much.


    Raghib Khesal
    KGCS
    raghib.netfirms.com

  10. #50
    Member
    Join Date
    Dec 2006
    Location
    Ontario, Canada
    Posts
    32

    Re: [Guide] Winsock - Chat Application

    Alright i dont know if this will help anyone but this connectionrequest code is from my chat server which can handle as many winsock controls that vb can open. If this has been posted or something similar to it i apologize but it works friggin great seeing as it checks for any unused sockets that are still open before making new ones so it recycles the old ones and keeps reusing them saves huge on memory

    VB Code:
    1. Private Sub sckData_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2.     Dim t1, t2
    3.     Dim i As Long, num As Long
    4.     If IsServerBanned(sckData(Index).RemoteHostIP) = "True" Then Exit Sub
    5. CheckSockets:
    6.     For i = 1 To sckData.UBound
    7.         If sckData(i).State = 0 Or sckData(0).State = 8 Then
    8.             sckData(i).Close
    9.             sckData(i).Tag = ""
    10.             sckData(i).Accept requestID
    11.             WriteToLog sckData(i).RemoteHostIP & " is attempting to connect", RGB(0, 0, 0)
    12.             sckData(i).SendData "gi" & Chr(10)
    13.             Exit Sub
    14.         End If
    15.         DoEvents
    16.     Next i
    17.     DoEvents
    18.     num = sckData.UBound + 1
    19.     Load sckData(num)
    20.     sckData(num).Accept requestID
    21.     WriteToLog sckData(i).RemoteHostIP & " is attempting to connect", RGB(0, 0, 0)
    22.     sckData(num).SendData "gi" & Chr(10)
    23. End Sub

    Just ignore the senddata stuff chat protocols and stuff

  11. #51
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: [Guide] Winsock - Chat Application

    That's basically the same idea of the code I posted in post #44

  12. #52
    New Member
    Join Date
    Sep 2006
    Posts
    5

    Re: [Guide] Winsock - Chat Application

    I'd like to thank y'all for making my life alot easier. I've used code based on this thread for a couple of years for several meteorological servers where I work. It works great!

    Does anyone have any idea how to do this stuff in VB2005? My research into this indicates you need about 10 times the amount of code to maybe achieve the same results.

  13. #53
    New Member Niko18's Avatar
    Join Date
    Apr 2007
    Location
    N.Y
    Posts
    9

    Re: [Guide] Winsock - Chat Application

    I dont have word, but i need the tut.

  14. #54
    Member
    Join Date
    Mar 2007
    Posts
    58

    Re: [Guide] Winsock - Chat Application

    Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
    newClient = wskClients.Count + 1
    Load wskClients(newClient)
    wskClients(newClient).Accept requestID 'accept the connection with our new Winsock
    End Sub

    Doesent work to me it say method member not found And sory i didtn place it in the VB code box becouse it sux and i dont know how to use it becouse im a idiot...

  15. #55
    Addicted Member
    Join Date
    May 2007
    Posts
    166

    Re: [Guide] Winsock - Chat Application

    instead of Local machine whether i can connect to Remote machine.

    i just created a combobox and inside that i have "localhost" and remote machine eg:"a1".
    if selected is localhost, it will connect. but if the selected item is a1(remote machine) it's not connecting.
    this the code i'm using....

    SEND
    ------
    Private Sub frmSend_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    comboBoxIP.Items.Add("localhost")
    comboBoxIP.Items.Add("a1")
    End Sub

    Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
    wsSend.Close()
    wsSend.Connect(comboBoxIP.Text, 1223) End Sub

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    wsSend.SendData(txtSendWhat.Text)
    End Sub

    RECEIVE
    --------
    Private Sub frmSend_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim frmReceive As New frmReceive
    frmReceive.Show()
    wsReceive.Close()
    wsReceive.LocalPort = 1223
    'wsReceive.RemotePort = 1223 wsReceive.Listen()
    End Sub

    Private Sub wsReceive_ConnectionRequest(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles wsReceive.ConnectionRequest
    If wsReceive.CtlState <> MSWinsockLib.StateConstants.sckClosed Then
    wsReceive.Close()
    End If

    wsReceive.Accept(e.requestID)

    If wsReceive.CtlState = MSWinsockLib.StateConstants.sckConnected Then
    Call wsReceiveConnected()
    End If
    End Sub

    Private Sub wsReceive_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles wsReceive.DataArrival
    Dim str As String
    wsReceive.GetData(str, vbString)
    txtMessageReceived.Text = str
    End Sub

    if i need to connect to a remote machine, what is the change i need to do in this code. i'm not getting anyidea.... if you know how to do that please let me know .
    thanks in advance and thanks for your post and link.. its very usefull for me...

  16. #56
    Addicted Member
    Join Date
    Jul 2008
    Location
    Guildford, UK
    Posts
    160

    Re: [Guide] Winsock - Chat Application

    I'm trying to do this at home but I cant find the winsock control? i even tried browsing for it and running a search but could not find it. I'm running Vista, is this why? how would i go about this project if so?

    "There'll be penguins on the moon"

  17. #57

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [Guide] Winsock - Chat Application

    Quote Originally Posted by paralyzedcitizen
    I'm trying to do this at home but I cant find the winsock control? i even tried browsing for it and running a search but could not find it. I'm running Vista, is this why? how would i go about this project if so?
    This is very old code Visual Baisc 6, what version are you using?

  18. #58
    Addicted Member
    Join Date
    Jul 2008
    Location
    Guildford, UK
    Posts
    160

    Re: [Guide] Winsock - Chat Application

    I'm using VB6. I know it's old and I should be using .net but my mate gave it to me and that's why i've learnt vb6. I have started to learn .net with 2005 but i prefer vb6 to be honest.

    "There'll be penguins on the moon"

  19. #59
    Addicted Member
    Join Date
    Jul 2008
    Location
    Guildford, UK
    Posts
    160

    Re: [Guide] Winsock - Chat Application

    *Bump*

    "There'll be penguins on the moon"

  20. #60
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: [Guide] Winsock - Chat Application

    paralyzedcitizen, why don't you start a new thread where you ask for your problem instead of "hijacking" a year old thread ?

    Make sure your thread title is about your problem, something like "Winsock on Vista"

  21. #61
    Addicted Member
    Join Date
    Jul 2008
    Location
    Guildford, UK
    Posts
    160

    Re: [Guide] Winsock - Chat Application

    paralyzedcitizen, why don't you start a new thread where you ask for your problem instead of "hijacking" a year old thread ?
    ?

    My query is directly related to this thread, I'm trying to make the chat application from the first post. Surely this thread couldn't be more relavent? And if I created a new thread I would most likely just get linked back here.

    "There'll be penguins on the moon"

  22. #62
    Junior Member
    Join Date
    Nov 2009
    Posts
    19

    Re: [Guide] Winsock - Chat Application

    yay men....its not working if you try to connect it using other computer to other computer...but do nice..

Page 2 of 2 FirstFirst 12

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