-
Jul 28th, 2005, 01:57 PM
#41
Re: [Guide] Winsock - Chat Application
When a client disconnects I normally unload the Winsock control that is associated with that client
VB Code:
Private Sub Winsock_Close(Index As Integer)
Unload Winsock(Index)
End Sub
-
Jul 28th, 2005, 02:20 PM
#42
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...
-
Jul 28th, 2005, 02:23 PM
#43
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.
-
Jul 28th, 2005, 02:27 PM
#44
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:
Private Sub SckTCP_Close(Index As Integer)
CClients = CClients - 1
SckTCP(Index).Close
ClearUser Index
If Index = 0 Then
ConnectAllSockets
End If
End Sub
Private Sub SckTCP_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim K As Integer, SHA As New clsSHA256, StrToSend As String
For K = 1 To SckTCP.UBound
If SckTCP(K).State = sckClosed Then Exit For
Next K
If K = SckTCP.UBound + 1 Then
Load SckTCP(SckTCP.UBound + 1)
Load tmrSendData(SckTCP.UBound)
ReDim Preserve Clients(SckTCP.UBound)
K = SckTCP.UBound
End If
Randomize
Clients(K).State = 0
Clients(K).CLogIn.RndINIT = UCase(SHA.SHA256(CStr((2 ^ 30) * Rnd)))
SckTCP(K).Accept requestID
StrToSend = "RndINIT|" & Clients(K).CLogIn.RndINIT
SckTCP(K).SendData Len(StrToSend) & ":" & StrToSend
CClients = CClients + 1
End Sub
-
Oct 7th, 2005, 05:38 PM
#45
New Member
Re: [Guide] Winsock - Chat Application
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
-
Oct 8th, 2005, 03:35 AM
#46
Thread Starter
Super Moderator
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
-
Oct 9th, 2005, 02:53 PM
#47
New Member
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
-
Oct 9th, 2005, 03:06 PM
#48
Thread Starter
Super Moderator
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
-
Mar 8th, 2006, 04:23 AM
#49
New Member
Re: [Guide] Winsock - Chat Application
Thanks
Because this codes helped me very much.
Raghib Khesal
KGCS
raghib.netfirms.com
-
Dec 14th, 2006, 08:59 PM
#50
Member
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:
Private Sub sckData_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim t1, t2
Dim i As Long, num As Long
If IsServerBanned(sckData(Index).RemoteHostIP) = "True" Then Exit Sub
CheckSockets:
For i = 1 To sckData.UBound
If sckData(i).State = 0 Or sckData(0).State = 8 Then
sckData(i).Close
sckData(i).Tag = ""
sckData(i).Accept requestID
WriteToLog sckData(i).RemoteHostIP & " is attempting to connect", RGB(0, 0, 0)
sckData(i).SendData "gi" & Chr(10)
Exit Sub
End If
DoEvents
Next i
DoEvents
num = sckData.UBound + 1
Load sckData(num)
sckData(num).Accept requestID
WriteToLog sckData(i).RemoteHostIP & " is attempting to connect", RGB(0, 0, 0)
sckData(num).SendData "gi" & Chr(10)
End Sub
Just ignore the senddata stuff chat protocols and stuff
-
Dec 14th, 2006, 11:01 PM
#51
Re: [Guide] Winsock - Chat Application
That's basically the same idea of the code I posted in post #44
-
Jan 24th, 2007, 03:03 PM
#52
New Member
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.
-
Apr 13th, 2007, 12:47 PM
#53
New Member
Re: [Guide] Winsock - Chat Application
I dont have word, but i need the tut.
-
Apr 17th, 2007, 12:56 PM
#54
Member
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...
-
May 18th, 2007, 02:02 PM
#55
Addicted Member
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...
-
Sep 30th, 2008, 05:50 AM
#56
Addicted Member
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"
-
Sep 30th, 2008, 05:55 AM
#57
Thread Starter
Super Moderator
Re: [Guide] Winsock - Chat Application
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?
-
Sep 30th, 2008, 07:06 AM
#58
Addicted Member
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"
-
Oct 1st, 2008, 03:29 AM
#59
Addicted Member
Re: [Guide] Winsock - Chat Application
"There'll be penguins on the moon"
-
Oct 1st, 2008, 09:36 AM
#60
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"
-
Oct 1st, 2008, 11:13 AM
#61
Addicted Member
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"
-
Nov 28th, 2009, 10:06 PM
#62
Junior Member
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..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|