• Welcome to Valhalla Legends Archive.
 

baisc help

Started by Nodda4you, May 18, 2005, 03:31 PM

Previous topic - Next topic

Nodda4you

im making a basic chat program. well, not even chat. just to understand winsock.
here's my code. It's not working

For the server...
Private Sub cmdConnect_Click()
Winsock1.LocalPort = 1234
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim TempData As String
Winsock1.GetData TempData
MsgBox TempData
End Sub


For the client
Private Sub cmdConnect_Click()
Winsock1.Connect
End Sub

Private Sub cmdSend_Click()
Dim data As String
data = "Testing 123"
Winsock1.SendData data
End Sub

Private Sub Form_Load()
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 1234
End Sub


I run it and click connect, and try sending, but it says
QuoteWrong protocal or connection state for the requested transaction or request

Hdx

Make sure to close the winsock before tryinhg to connect.
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Nodda4you

On which? Client or server?
I have it for the server..

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub


and if i need it for the client, where do i put it? and would it still be

Winsock1.close
?

Hdx


Private Sub cmdConnect_Click()
                            <~~~~poke
Winsock1.Connect
End Sub

~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

OnlyMeat

Im assuming it's because you are not selecting the protocol either udp or tcp/ip. This can be done on the form load.

Hdx

Winsock in VB defults to TCP\IP upon adding the object. But that could be the problem
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Nodda4you


Private Sub cmdConnect_Click()
Winsock1.Close
Winsock1.Connect
End Sub

Tontow

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub


why is your server closeing the connection befor accepting it?????  Thats like hangeing up the phone befor saying hello.



Hdx

First it's listening, so it has to stop listening, then accept the connection.
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

LivedKrad

Why not set a conditional to check the connection state before sending? That way you can see if you're even connected at all.

Nodda4you

How do I do that?

Hdx

winsock.State
sckConnected
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

111787

you are probably going to want to use an array of sockets.  Otherwise you can only have one connection to the server.

Nodda4you

Where would I put

winsock.State
sckConnected

Tontow

Quote from: Nodda4you on May 18, 2005, 08:07 PM
How do I do that?

put this in a timer


Select Case socket.State
   Case 0
       form.Caption = "Closed"
   Case 1
       form.Caption = "Open"
   Case 2
       form.Caption = "Listening"
   Case 3
       form.Caption = "Connection pending"
   Case 4
       form.Caption = "Resolving host"
   Case 5
       form.Caption = "Host resolved"
   Case 6
       form.Caption = "Connecting"
   Case 7
       form.Caption = "Connected"
   Case 8
       form.Caption = "Peer is closing the connection"
   Case 9
       form.Caption = "Error"
End Select