|
-
Oct 30th, 2002, 05:27 PM
#1
Thread Starter
Addicted Member
Winsock.SendData problem with strings*unresolved*
Hi all just a quick question:
Can you send a string using senddata through a network
VB Code:
Private Sub Runner_Timer()
Dim Sendoff As String
Info = Time
lblInfo.Caption = Info
lblCompNam.Caption = ComputerNME
lblIP.Caption = IP
Sendoff = Info & "*" & ComputerNME & "*" & IP
Winsuck.SendData Sendoff
End Sub
I keep on getting a error "Wrong protocol or connection state for the requested transaction or state"
I am using TCP, I know it works in UDP.
anybody have any clues
Thanks in advance
Last edited by Booda; Oct 30th, 2002 at 07:39 PM.
-
Oct 30th, 2002, 05:57 PM
#2
Thread Starter
Addicted Member
is this such a bad question that no one would look at it even?
-
Oct 30th, 2002, 06:07 PM
#3
Lively Member
Hehehe.
You have to set the type to AF_INET, the socket stream to SOCK_STREAM, and the protocol to IPPROTO_TCP. Then it'll work.
-
Oct 30th, 2002, 06:12 PM
#4
Thread Starter
Addicted Member
Wow !! I a bit a of a ......no i AM a newbie to winsock programming, where do you set the type, socket stream.
As for the protocol I have 2 choices sckTCPProtocol and
sckUDPProtocol
Sorry bout that, I just have no clue yet
-
Oct 30th, 2002, 06:24 PM
#5
Frenzied Member
OK, this Might sound dumb, but have you created a connection yet?
And u didnt close it or that (did u?)
VB Code:
' If the Connection Socket on the MainClient is open, Close it
If frmMainClient.ConnSock(0).State <> sckClosed Then frmMainClient.ConnSock(0).Close
' Set the connection socket properties
frmMainClient.ConnSock(0).RemoteHost = Me.cboServerName.Text
frmMainClient.ConnSock(0).RemotePort = Me.cboPort.Text
' Connect to the server
frmMainClient.ConnSock(0).Connect
' Give the connection Four tries, and if it fails, tell the user
Do Until frmMainClient.ConnSock(0).State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If frmMainClient.ConnSock(0).State = sckError Then
MsgBox "There was a problem when trying to connect to the chat server!" _
& vbCrLf & "Either the server is down, or you aren't connected to the Internet", vbOKOnly, "Connection Error"
Exit Sub
End If
Loop
frmMainClient.ConnSock(0).SendData (SendOff)
Make the WinSock called "ConnSock" and an index of 0, if u dont plan on editing the code (You still need to edit the form name.
frmMainClient = Form1, MyForm, ETC
This should work?
: Psst, be a little more descriptive with Titles Too .. Mite help people, cuz a lot of ppl only enter a thread if they *think* they will be able to A)Learn from it, or B)Help you 
Any how, see how that goes for u
-
Oct 30th, 2002, 06:55 PM
#6
Thread Starter
Addicted Member
yeah I did create the connection, i have done this before using sclUDPProtocol and it did work with a string, now that I'm using TCP, I seem to be having a problem
Yes the connection has been made, i did close it before opening it, and the IP and port numbers are all in check
Thanks for the responces and the extra help too
-
Oct 30th, 2002, 07:20 PM
#7
Frenzied Member
: OK, Well not exactly sure what it is then (I am a newbie [bout 1 / 2 weeks tops] working with WinSock Myself )
-
Oct 30th, 2002, 07:31 PM
#8
Thread Starter
Addicted Member
well thanks for the response anyways, this winsock thing seems to be a bit of an enigma to me.
oh well tomorrow is another day
-
Oct 30th, 2002, 08:26 PM
#9
The picture isn't missing
well... i don't think it's that code problem. show us your other code as well.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Oct 30th, 2002, 09:40 PM
#10
Thread Starter
Addicted Member
ok here is a list of the form:
3 labels
lblinfo
lblcompnam
lblip
a command button called cmdSS
a Timer called Runner
winsock control call Winsuck (sorry just had to do it, and I'm sure I'm not the first)
what I want this program to do is to just send out the system time of the computer, the name of the computer and the ip address.
so heres the code:
VB Code:
'CODE IN THE FORM
Option Explicit
Dim ComputerNME As String
Dim Info As String
Dim IP As String
Dim TBuff() As Byte
Private Sub cmdSS_Click()
If cmdSS.Caption = "Start" Then
Runner.Enabled = True
cmdSS.Caption = "Stop"
Else
Runner.Enabled = False
cmdSS.Caption = "Start"
End If
End Sub
Private Sub Form_Load()
Dim dwlen As Long
cmdSS.Caption = "Start"
lblInfo.Caption = ""
lblCompNam.Caption = ""
lblIP.Caption = ""
dwlen = MAX_COMPUTERNAME_LENGTH + 1
ComputerNME = String(dwlen, "X")
GetComputerName ComputerNME, dwlen
ComputerNME = Left(ComputerNME, dwlen)
IP = Winsuck.LocalIP
Runner.Interval = 5000
Winsuck.Close
Winsuck.RemoteHost = "192.168.0.131"
Winsuck.RemotePort = 5150
Winsuck.Connect
End Sub
Private Sub Runner_Timer()
Dim Sendoff As String
Info = Time
lblInfo.Caption = Info
lblCompNam.Caption = ComputerNME
lblIP.Caption = IP
Sendoff = Info & "*" & ComputerNME & "*" & IP
Winsuck.SendData Sendoff
End Sub
'CODE IN A MODULE
Option Explicit
Public Const MAX_COMPUTERNAME_LENGTH As Long = 51
Declare Function GetComputerName Lib "KERNEL32" Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, _
ByVal cbCopy As Long)
now the line that gives me the problem is:
Winsuck.SendData Sendoff
thanks for taking a look at this!!
-
Oct 30th, 2002, 09:47 PM
#11
Frenzied Member
Try:
VB Code:
Winsuck.SendData(Sendoff)
-
Oct 30th, 2002, 09:50 PM
#12
Thread Starter
Addicted Member
yeah I tried that and got the same error
-
Oct 30th, 2002, 09:54 PM
#13
Frenzied Member
:Wonders...
Try and make a control array for the "Winsuck"
Make the Index = (0)
And change Winsuck. to Winsuck(0).
Other then that, i can only think that, your server could be faulting?
What is the error msg caused?
-
Oct 30th, 2002, 10:00 PM
#14
Frenzied Member
VB Code:
'CODE IN THE FORM
Option Explicit
Dim ComputerNME As String
Dim Info As String
Dim IP As String
Dim TBuff() As Byte
Private Sub cmdSS_Click()
If cmdSS.Caption = "Start" Then
Runner.Enabled = True
cmdSS.Caption = "Stop"
Else
Runner.Enabled = False
cmdSS.Caption = "Start"
End If
End Sub
Private Sub Form_Load()
Dim dwlen As Long
cmdSS.Caption = "Start"
lblInfo.Caption = ""
lblCompNam.Caption = ""
lblIP.Caption = ""
dwlen = MAX_COMPUTERNAME_LENGTH + 1
ComputerNME = String(dwlen, "X")
GetComputerName ComputerNME, dwlen
ComputerNME = Left(ComputerNME, dwlen)
IP = Winsuck.LocalIP
Winsuck.Close
Winsuck.RemoteHost = "192.168.0.131"
Winsuck.RemotePort = 5150
Winsuck.Connect
' Give the connection Four tries, and if it fails, tell the user
Do Until Winsuck.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsuck.State = sckError Then
MsgBox "There was a problem when trying to connect to the server!" _
, vbOKOnly, "Connection Error"
Exit Sub
End If
Loop
Runner.Interval = 5000
Runner.Enabled = False
End Sub
Private Sub Runner_Timer()
Dim Sendoff As String
Info = Time
lblInfo.Caption = Info
lblCompNam.Caption = ComputerNME
lblIP.Caption = IP
Sendoff = Info & "*" & ComputerNME & "*" & IP
Winsuck.SendData Sendoff
End Sub
Check that.... Might work, might not (Worth a shot tho huh )
-
Oct 30th, 2002, 10:12 PM
#15
Thread Starter
Addicted Member
well I'll have to try that one when I get back into work tomorrow (currenly at home)
I see what you did, and I do understand what you're getting at
Thank you very much for the help, I will try this and try to reply on this thread again
-
Oct 30th, 2002, 10:13 PM
#16
-
Oct 31st, 2002, 12:11 AM
#17
PowerPoster
Winsock1.Listen on the server
and make sure you have the correct ip address and port set for computers. And maybe use a If Winsock1.state <> sckclosed....
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
|