Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Winsock State 8 - Peer Closes The Connection Leaving Winsock High And Dry


I am debugging some web/proxy-serving code. I am stumped.

I get Winsock state 8 - Peer is closing the connection
Then Winsock error message wrong protocol or connection state.

It seems to me that Winsock closes before it can finish sending all of its data.

How can I keep Winsock in state 7 - Connected?


Thanks...




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Winsock Connection State
I have created a server-client project with winsock. Server maintains a list of connected clients. Then I do following:

I Disable client's LAN
I View the state property of winsock control reffering to that client on server.
It shows 7 (Connected). Why ??. It should be 9.
This state doesn't get refreshed for a long time. Why this is so ??

How to determine is client connected or not. I mean a correct way which tell me client is really connected/disconnected.

Winsock Connection State Problem
I have just tried out an application I have written some time ago that uses winsock to connect to a second application for the purpose of license checking. It is a new higher spec PC - P4 1.6, 512MB ram, old PC was P3 800 512MB.

However i have ran into a problem with winsock in that when when the client sends a connection request to the server socket, when the data arrives back to the client and I try to get the data from the buffer, I get an error message telling me the connection state is still connecting. What gives!!??

Example Code:

Client :


PHP Code:




Sub ConnectToServer

If sckClient.State <> sckClosed Then sckClient.Close

sckClient.RemoteHost = regx.Server
sckClient.RemotePort = "1001"
sckClient.Connect

End Sub







Server :


PHP Code:




Private Sub sckServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)

    sckServer.LocalPort = 1001
    sckServer.Accept requestID
    sckServer.SendData "READY#"
        
End Sub







Client :


PHP Code:




Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)

    Dim strData as String

    '// I get an error here telling me the connection state is wrong
    '// The connection state shows up to be 6 - connecting
    '// However no matter how long I wait, the state stays at 6
    '// I have tried a loop with a doevents to yield to the processor
    '// so that everying gets processed before continuing but no joy
    
    sckClient.GetData strData

End Sub







It used to all work so well .......

Winsock Connection State Times Out
Hello,

I am pulling my hair out here. I am working on a polling system to retrieve files from my company's store locations via winsock. The client request, however, just returns sckConnecting as a state until it eventually times out. I have other apps that use winsock that work. what am i doing wrong.

Client App is something like this...

'Request file from remote host...
'Close first...
If frmStatus.wskOutbound.State <> sckClosed Then
frmStatus.wskOutbound.Close
End If

'Attempt to connect...
frmStatus.wskOutbound.Protocol = sckTCPProtocol
frmStatus.wskOutbound.RemoteHost = "192.1.1.240"
frmStatus.wskOutbound.RemotePort = "2400"
frmStatus.wskOutbound.Connect


'Start the timeout timer...
StartTime = Timer

'loop until connected or timeout (whichever comes first)
Do While (frmStatus.wskOutbound.State <> 7) And (Timer - StartTime < TimeoutSeconds)
DoEvents
Debug.Print frmStatus.wskOutbound.State

Server app is something like this...

Form Load()

Me.wskInbound.Protocol = sckTCPProtocol
Me.wskInbound.LocalPort = "2400"
Me.wskInbound.Listen


Private Sub wskInbound_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next

If Me.wskInbound.State <> sckClosed Then
Me.wskInbound.Close
End If

wskInbound.Accept requestID

No matter what I do it always stays in state 6 and never moves into state 7

Thanks Much

How To Open And Modify Share Database, Peer To Peer Connection
hi, guys

i'm new in this forum. i need ask about share database on peer to peer connection.
i alrready created windows application using vb 6.0 and microsoft access 2000.
I have 2 pc that connect trough peer to peer connection. The operating system is Windows 98 SE.

The application was installed on pc no 1, and on pc no 2 i maked shortcut of the exe file that i take from share folder on pc no 1. The share mode is full control access(read,write,execute).

The program was open on pc no 1, and when i try to open the program on pc no 2, i got error. I can't connect to the database.

this is my connection code :

Public Sub OpenDB(lngMode As ADODB.ConnectModeEnum, _
                        Optional strPath As String, Optional strDBPwd)
                        
    
    On Error GoTo ErrConn
    
    With cnnDB
        .Mode = lngMode
        .Provider = "Microsoft.jet.OLEDB.4.0"
        .Properties("Jet OLEDBatabase Password") = strDBPwd
        .Open ConnectionString:=strPath
    End With
Exit Sub
ErrConn:
    MsgBox "Connection Failed", vbCritical + vbOKOnly, "Connection Informaiton"
    Exit Sub
End Sub


lngMode is admodesharedenynone
strpath is App.Path & "DatabaseMummy.mdb"
i'm using the blank password for the db--> strDBPwd = ""


can u guys help me ??

Force Re-Connection Of Peer-Peer Mapped Drive
Hi Guys.

Consider this, I have a simple 3-machine Peer-Peer network using XP. Two machines are XP Pro, the other is XP Home.

I have two mapped drives which are set to re-connect at logon.

If however the machines boot up in the "wrong" order then the network drive appears disconnected.

If you double-click on that drive from My-Computer it immediately establishes connection and everything is ok from that point on, however, if you try to access the drive from code an error is returned saying the drive is unavailable, SO...

how do I force XP to attempt to re-connect the drive using VB?

Ps. For a long and complicated reason, I CANNOT try to access the path using \pigmyscomputerfoldername it HAS to be using the mapped drive letter.

Help!

Thanx


Pigmy

Is It Possible To Have A Peer-to-peer Connection With Out A Server?
Hi,

Is it possible to have a peer-to-peer connection with out a server?

Winsock.state
how can we actually detect winsock.state=9 (connection is closed by peer). well, i've put this line in a timer (1000 ms interval) :


Code:
private sub timer1_timer()
if tcpServer.state=9 then Reconnect
end sub

sometimes it works... but most of times, tcpserver.state returns 7 even remote computer is off. sorry for my extraordinary bad english

Winsock State
is there a way to know/detect if client disconnected without trigering .close event (like when clien application crashed & terminated)

How To Know Winsock State?
how to know winsock state connected?

Winsock State
ok i made a chat software working fine..

first the server listening
client login server create an instace of winsock control and send data works fine...


those contact shows in a list box at client side..
when user click any user in list box it's open another form for chat.

here user type his msg and click send button.
the code of send button is
the main form name is frmclient
and the chat form name is frmChat

VB Code:
frmclient.wskclient.senddata txtchat.text


i got the following error:
wrong protocol or connection state for the requested transaction or request

when i check the state of the frmclient.state in immidate window it's shows 0
if i focus the frmclient and write the code in immidiate window

?me.wskclient.state it's shows 7
but if i wrote
?frmclient.wskclient.state it's shows 0

can any one tell me how i send the msg to other

State Of Winsock
What are the specific states of winsock. I believe they are numbers like 1 = connected 2 = disconnected or something.

Winsock State
I am trying to Create an app like Yahoo Messenger.

When I send Data From the Client End it reaches the server end. ( that is the other end.) but when I want to send back the data to the client it gives a 40006 error. which is basically the STATE problem.

I have checked the State of both end. the Server end is 2 = Listen and the Client End is always '6=Connecting.

When it is sendning the data why it is not changing the state to 7 = connected.

Can U gide me please.....

Winsock Multi High Speed Connections
I've ran out of ideas without getting elaborate in the sending/verifying. Maybe I am missing something easy...

One server. Loads a new instance of the winsock control with a new connection - similar to the help examples...

Each client has a single winsock control successfully connecting and transmitting to the server.

The server then retransmits the data back out to all the other connected clients.

Works ok, but at 4 transmits a second of 2k of data, the "slow" connection clients sometimes get a send complete event however the data does not always get back out to the other clients (such as one of my wireless PC's vs a couple wired ones).

I'm not sure how to efficiently deal with this. If I made the clients wait until the data is retransmitted, a slow connection will bog everyone down. If I stored the data to be sent for slower connection PC's, I will lose something unpredictable.

My next thought would to be to divide up the data into small groups of data and send those that are critical or has actually changed since the last transmit - but I don't know if I spent the time if this would help. Sending one bit of data may not be much different than sending 100 bytes due to overhead... 100 bytes may not be any different that 2k... don't know. 2k doesn't sound like much, but it might be. Say 4 clients, 16,000 bits ea, that's 128kb a second??? Doubling it for the server resending .... er wait, that's exponential for each client... I think I see my problem... maybe...

Thanks for any advice or pointers in high speed multi-clients...

Winsock State Numbers
Hey, I used to have a list of Winsock State numbers, but I have misplaced it. Anyone got a list for me? and can possibly email me them liamfoy@sepulcrum.org

Cheers Guys.

Winsock Wrong State
Hi,

I'm trying to connect a client application with a Server application both of them in the same machine, but I'm not getting connection anytime. I check the state and I get:

- for the remotehost = "localhost" I get state = 4.
- for the remotehost = "127.0.0.1" I get state = 6.

I never get the state = 7 (connected). My code is the following:


Code:
Private Sub Timer_control_Timer()
Dim rc As Boolean
For i = 0 To 3

socket_1.LocalPort = 2000
socket_1.RemoteHost = ip_address(i)
socket_1.RemotePort = port(i)

socket_1.Connect

rc = check_wnpa()

socket_1.Close

If rc = False Then
MsgBox "Apagado"
Else
MsgBox "Encendido"
End If
Next i
End Sub

Private Function check_wnpa() As Boolean
' Function to check the status of the WNPA Server
On Error GoTo Error_Check_Server


check_wnpa = False

If socket_1.State = sckConnected Then
socket_1.SendData Chr(6)
'socket_1.GetData str
check_wnpa = True
Else
check_wnpa = False
End If

socket_1.Close

Exit Function

Error_Check_Server:
MsgBox "Error #" & Err.Number & ": " & Err.Description
End
End Function
Anybody can help me and tell me what is happening.

Thanks in advance

Winsock State During Telnet
I have a simple telnet program that opens the connection successfully, runs a few scripts via a command button I need and then closes.

All this done with command buttons and works fine.

cmdConnect
cmdScript
cmdDisconnect

If you do not connect before you push the cmdScript button it gives an error first. I would like to combine these to one button....

I did this...but... when if it disconnects for whatever reason it errors out. I tried the sck.state but regardless if I am connected or disconnected it returns the same value.

Anyone know what I am doing wrong. Here is what I tried, but it returns the same value regardless if it is open of closed:


Code:
If rsh.mState = 0 Then
MsgBox "Connection has been lost. Please reconnect."
HideButtons
Timer1.Enabled = False
End If
Thanks for your help,
ErocM

Winsock State Stuck On 6
Hi all, my winsock is stuck on 6.I have a loop until state = 7 but the state never gets to 7. Please help me.

Thanks in advance

Winsock.State Question
Hi all,

I tried to write a winsock application, but I cannot understand something:


VB Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Form_Load() Winsock1.Connect "127.0.0.1", 445 Sleep 1000  MsgBox Winsock1.StateEnd Sub


If I run this code, the state is always 6, and not depends on sleep value.
But, if I add another msgbox, before the state, the state will be correct - 7:


VB Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Form_Load() Winsock1.Connect "127.0.0.1", 445 Sleep 200  MsgBox ".." MsgBox Winsock1.StateEnd Sub


Why shows the current state only, when I add another msgbox before it???

Thanks.

WinSock State Problem
I was two applications (Server and Client). When the client application exits, I use WinSockControl.Close to close the connection. But when I open the application up again, the connection errors out and doesn't connect to server. I tried solving the problem by on the Server application, having it at state "Closing" to switch state to "Listening" but the Client still won't connect. I must exit both Server and Client, then start Server before I start Client. Any suggestions on possible solutions?

WinSock.State = SckOpen
Hiya,

Im using the WinSock control and found this state
called sckOpen but I have no idea what this means!

Well I created a little App to test this out and after
some connect/disconnects I got this: When I click
Connect state changes to 1 (sckOpen) and nothing
more happens. Also Listen and then Connect does
not work anymore!

Also weird is I sometimes get Error 10048 (Address
already in use) when I try to Connect or Listen.. I
catched the error but I dont like this happening at
all!

Is anyone familiar with the WinSock states?

Regards,

Fox

Winsock .State Problem
I have a little winsock problem. First off all, i hate the tutorial on vbforums, because it doesn't work and most people seem to have problem with it. So please, no referrals to that tutorial please.

I have 2 forms, and a server and one client. I have 2 textboxes on both forms, and 3 buttons. Connect, disconnect and send. On connect, the client makes connection (tcpClient.Connect), but it will only do it if the server (tcpServer.Listen) is running. When i press disconnect, it closes the connection, but when i press connect again, it will not connect. It goes from state 0 to 6 (connecting), state 7 (connected) en 8 (closing). Why can i not get it to connect again? It connects for a brief moment, then it closes again. Anyone got some help on this one?

ps: i took the sample from the msdn file, so it works, then i started to add things. The final objective is to make it a messenger program with datatransfer possibilities.

Winsock Connecting State, Loop
Private Sub mnuFileConnect_Click()
On Error Resume Next
Dim iServ As String

iServ = "ipnumber"

If iServ = "" Then Exit Sub

'Disable menus
frmMain.mnuFileConnect.Enabled = False
frmMain.mnuFileExit.Enabled = False

'Connect to the server
With wsk
.Close
.Protocol = sckTCPProtocol
.RemotePort = ServerPort
.RemoteHost = iServ
.Connect
End With

Call ShowText("Connecting to server" & vbCrLf & vbCrLf)
StatusBar2.Panels(1).Text = "Status: Connecting"
End Sub

----------------------------------
THIS IS PART OF THE SUB i took from my game, the connecting part.. can sombody please modify it, to check the connection state and make it write it to the statusbar,, and also if winsock state is 0, not connected.. then it will keep on trying to connect.. the problem with my code is.. if the server aint up.. u have to keep reconnecting, because it dont like loop... please help

Winsock State.. MAIL_CONNECT Or MAIL_HELO
I'm following a Winsock email send from this tutorial: http://www.vbip.com/winsock/winsock_simple_sender.asp.

When testing this Im using smtp.gmail.com, port 465 and 587 also have tried the default port 25. gmail suggests 465 and 587.

When sending this is the output I get back.

SMTP: smtp.gmail.com
Port 587
220 mx.gmail.com ESMTP 16sm353283nzo
502 5.5.1 Unrecognized command 16sm353283nzo


I've debugged to the point where I know MAIL_CONNECT is completes and when MAIL_HELO starts is where my issue is.

I can not figure out why this is happening. Actually, I have an idea. I have successfully tested this lil app using mail.lttf.com which is my smtp from my work. But I do not want to use that to send the email, I wish to use gmail.com.

Any help?

Winsock Stuck On State 6 (Connecting?)
Hello,

The client is stuck on state 6 (I think it mean connecting) but the server shows state 7 (Connected?)

How can I fix this problem?

They are both running on the same machine.

Thanks,

Tom

How To Detect Winsock State Change?
anyone know?
i need to know when its state changse to "8"

Winsock Port Seems To Get Stuck In The 6 State.
Even after I have closed the program and all winsock controls... the next time I run the app, I seem to get stuck in state 6... is there a reason for this or anything I can do to flush the port as I am shutting down or starting up?

While Loop Problems When Using Winsock.state
Hi,

Below is the Client code that i'm trying to run. CmdPosition and CmdSend both require that WinsockID is connected to the server and therefore cant execute without waiting for this event to take place, hence to While loop. Problem is that the while loop doesn't ever seem to exit, that is, the client doesn't load, stops responding and CPU usage goes up to 100%. I've tried the loop using an integer match i.e. WaitCount = 10 and this is fine. It just seem to be having trouble with the winsock.state command. It works fine if you do a "step into" debug so it looks to me like its some sort of time problem? I've also tried other variations of the while loop (Loop Until WinsockID.State = sckConnected etc) but all give the same result. Any help greatly appreciated.

Private Sub Form_Load()

CmdConnect_Click

Dim WaitCount As Long
WaitCount = 1
Do
WaitCount = WaitCount + 1
Loop While WinsockID.State <> sckConnected

' RUN TESTS NOW LOADED AND CONNECTED.

cmdPosition_Click
cmdSend_Click
cmdPosition_Click
cmdSend_Click

End Sub

Winsock Control State Values
Hi i was wondering if someone can link me to a reference of winsock state values.


Thanks

[--HOPE THIS HELPED--]
Matt

An Array To Check For Winsock State?
Hey, I'm running a program that uses four Winsock controls (each on a different port). What I want to do is, during Form_Unload, I want to check if any of them have a .State = 7 (meaning it's an open connection). If there is an open connection, then I want THAT specific Winsock to send a message "999" (which is my code for telling the client computer to disconnect itself). This is how I am doing it right now.

Code:
Private Sub Form_Unload(Cancel As Integer)

    If Winsock1.State = 7 Then
        Winsock1.SendData "999"
        Winsock1.Close
    End If

    If Winsock2.State = 7 Then
        Winsock2.SendData "999"
        Winsock2.Close
    End If

    If Winsock3.State = 7 Then
        Winsock3.SendData "999"
        Winsock3.Close
    End If

    If Winsock4.State = 7 Then
        Winsock4.SendData "999"
        Winsock4.Close
    End If

End Sub


However, I thought it would be a lot cleaner (and easier to maintain if I should increase the number of Winsocks in my program) to do this as an array. I do NOT know a lot about arrays (actually, I know almost nothing about them). I found this code and tried to implement it but am running into a problem.

Here's the code for the array that I tried using:

Code:
Private Sub Form_Unload(Cancel As Integer)

    Dim i As Integer
    For i = 1 To 4
        If Winsock(i).State = 7 Then
            Winsock(i).SendData "999"
                DoEvents
            Winsock(i).Close
        End If
    Next i

End Sub


However, when I run this code, I get this error:

Quote:Compile error:

Sub or Function not defined


And in VB it highlights the "Winsock" part of this line of code: "If Winsock(i).State = 7 Then"

Can anyone tell me what I am doing wrong in this array? As I said, I am very new to arrays (and the VB in general). I'm not sure if the problem is in how I tried doing this or in my array or in the winsock statement.

Any help would be GREATLY appreciated. Thanks in advance.

DTFan

Winsock.State - Still Connected Or Not? *Resolved*
Hey, i got a problem retrieving the current Winsock status, the client side is a php script that connects, sends and retrieves a single string and then closes the socket, but the winsock at the sever keeps saying the connection is still active. And can't wait for a new connection as i let it set to listen mode when the connection is closed.

The way i was doing this was putting a "Select Case Winsock1.State" event in a timer to check the status,
(0 = inactive, 2 = listen, 8 = connected).

But the state stays saying Connected and because of this it doesn't put itself in auto-listen mode again.

Is there another way to check if the connection is still active or not? thanks at front.


EDIT :
-------

problem solved, feel a bit silly tough, was browsing a bit around here on vbcity, what did i see, Winsock1_Close()...

Sorry guys from VBcity for this waste of post.









Edited by - T48 - [RedPlanet] on 5/15/2004 11:25:59 AM

Winsock - Invalid Operation At Current State
Hi,

I have notice that this error has happened alot. But Google has failed me on finding the solution.

When my client server program connects to each other, the client seems to drop connection and i get the error. I think its the command Winsock1.Accept requestID causing the error, but i dont know why my client is dropping connection before i can accept its connection

So, can any of you find what i done wrong and help me find the solution to this problem

Here is my code, I am a newby to vb, but i have done this kind of stuff in Java.


Code:
Private Sub cmdConnect_Click()
Winsock1.Connect "127.0.0.1", 4444


End Sub

Private Sub cmdDisconnect_Click()
Winsock1.Close
End Sub

Private Sub cmdSend_Click()
Dim data As String
data = txtInput.Text
Winsock1.SendData data & vbCrLf
End Sub

Private Sub cmdServer_Click()
Winsock1.LocalPort = 4444
Winsock1.Tag = 1
Winsock1.Listen
Label1.Caption = 1

End Sub



Private Sub Timer1_Timer()
If Winsock1.State = 0 Then
cmdState.Caption = "Closed"
End If
If Winsock1.State = 1 Then
cmdState.Caption = "Open"
End If
If Winsock1.State = 2 Then
cmdState.Caption = "Listening"
End If
If Winsock1.State = 3 Then
cmdState.Caption = "Pending"
End If
If Winsock1.State = 4 Then
cmdState.Caption = "Resolving Host"
End If
If Winsock1.State = 5 Then
cmdState.Caption = "Host Resolved"
End If
If Winsock1.State = 6 Then
cmdState.Caption = "Connecting"
End If
If Winsock1.State = 7 Then
cmdState.Caption = "Connected"
End If
If Winsock1.State = 8 Then
cmdState.Caption = "Error"
End If
End Sub

Private Sub Winsock1_Close()
VBA.Beep
txtText.Text = "Connection closed"
End Sub

Private Sub Winsock1_Connect()
txtText = "Connected " + Winsock1.RemoteHostIP
VBA.Beep

End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)

Winsock1.Accept requestID



End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData data
txtText.Text = data
End Sub

Private Sub Winsock1_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)
VBA.Beep
txtText.Text = Description
End Sub
Thanks in advance

WINSOCK: Invalid Operation At Current State
hiya all,

I got this little problem which i hope someone can help me with

I wrote this application for a friend, a kinda contact/business administration uitlity, and it works fine.

Currently he has over a thousand contacts in the database who are all customers of his, he services and maintains their machines etc... and asked me to write something to help him send circulars, bullins etc to them.

The problem is that when i send to a single email it works fine but when i send to multiple emails it gives the following error:

WINSOCK: Invalid Operation at Current State

I guess that its not completed sending the first email when its attempting to send to the next customer in the list and thats what causes the error.

SOME of the code i'm using is listed below :

The send button code

Code:
Private Sub cmdSend_Click()
Stop
Dim i As Integer
Dim counta As Integer

'--> give connect prompt
Title = "Information."
Msg = "Please ensure you are connected to the internet and then:" & vbCrLf & vbCrLf
Msg = Msg & Space$(10) & "Click 'Ok' to continue" & vbCrLf
Msg = Msg & Space$(10) & "Click 'Cancel' to quit" & vbCrLf
Answer = MsgBox(Msg, 33, Title)
If Answer <> 1 Then Exit Sub

'If Winsock1.State <> 7 Then Exit Sub


For counta = 0 To List1.ListCount - 1
If List1.Selected(counta) = True Then
txtRecipient = List2(1).List(counta)
'prepare attachments
For i = 0 To lstAttachments.ListCount - 1
lstAttachments.ListIndex = i
m_strEncodedFiles = m_strEncodedFiles & UUEncodeFile(lstAttachments.Text) & vbCrLf
Next i
Winsock1.Connect Trim$(txtHost), 25
m_State = MAIL_CONNECT
End If
Next

Winsock1.Close

End Sub





and the winsock code

Code:
Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Stop
Dim strServerResponse As String
Dim strResponseCode As String
Dim strDataToSend As String

'Retrive data from winsock buffer
Winsock1.GetData strServerResponse

Debug.Print strServerResponse

'Get server response code (first three symbols)
strResponseCode = Left(strServerResponse, 3)

'Only these three codes tell us that previous
'command accepted successfully and we can go on
Select Case strResponseCode
Case "250", "220", "354"
Select Case m_State
Case MAIL_CONNECT
'Change current state of the session
m_State = MAIL_HELO
'
'Remove blank spaces
strDataToSend = Trim$(txtSender)
'
'Retrieve mailbox name from e-mail address
strDataToSend = Left$(strDataToSend, InStr(1, strDataToSend, "@") - 1)
'Send HELO command to the server
Winsock1.SendData "HELO " & strDataToSend & vbCrLf
'
Debug.Print "HELO " & strDataToSend
'
Case MAIL_HELO
'
'Change current state of the session
m_State = MAIL_FROM
'
'Send MAIL FROM command to the server
Winsock1.SendData "MAIL FROM:" & Trim$(txtSender) & vbCrLf
'
Debug.Print "MAIL FROM:" & Trim$(txtSender)
'
Case MAIL_FROM
'
'Change current state of the session
m_State = MAIL_RCPTTO
'
'Send RCPT TO command to the server
Winsock1.SendData "RCPT TO:" & Trim$(txtRecipient) & vbCrLf
'
Debug.Print "RCPT TO:" & Trim$(txtRecipient)
'
Case MAIL_RCPTTO
'
'Change current state of the session
m_State = MAIL_DATA
'
'Send DATA command to the server
Winsock1.SendData "DATA" & vbCrLf
'
Debug.Print "DATA"
'
Case MAIL_DATA
'
'Change current state of the session
m_State = MAIL_DOT
'
'So now we are sending a message body
'Each line of text must be completed with
'linefeed symbol (Chr$(10) or vbLf) not with vbCrLf
'
'Send Subject line
Winsock1.SendData "Subject:" & txtSubject & vbLf & vbCrLf
'
Debug.Print "Subject:" & txtSubject
'
Dim varLines As Variant
Dim varLine As Variant
Dim strMessage As String
'
'Add atacchments
strMessage = txtMessage & vbCrLf & vbCrLf & m_strEncodedFiles
'clear memory
m_strEncodedFiles = ""
'Parse message to get lines (for VB6 only)
varLines = Split(strMessage, vbCrLf)
'clear memory
strMessage = ""
'
'Send each line of the message
For Each varLine In varLines
Winsock1.SendData CStr(varLine) & vbLf
'
Debug.Print CStr(varLine)
Next
'
'Send a dot symbol to inform server
'that sending of message comleted
Winsock1.SendData "." & vbCrLf
'CompleteSending
'
Debug.Print "."
'
Case MAIL_DOT
''Change current state of the session
'm_State = MAIL_QUIT
''
''Send QUIT command to the server
'Winsock1.SendData "QUIT" & vbCrLf
''
'Debug.Print "QUIT"
Case MAIL_QUIT
'
'Close connection
Winsock1.Close
'
End Select
Case Else
'If we are here server replied with
'unacceptable respose code therefore we need
'close connection and inform user about problem
'
Winsock1.Close
'
If Not m_State = MAIL_QUIT Then
MsgBox "SMTP Error: " & strServerResponse, vbInformation, "SMTP Error"
Else
MsgBox "Message sent successfuly.", vbInformation
End If
End Select

End Sub




I hope someone can help......

DocZaf
{;->

Winsock Error Message: Invalid Operation At Current State!!
what is the meaning of this error message : Invalid operation at current state??

Winsock Error 40020 : Invalid Operation At Current State
Hi
I have developed an messaging system which accepts multiple connections. I am getting this error on server side in ConnectionRequest procedure. I am not getting what is the problem ?

Here is some code :


VB Code:
Private Sub Close_Socket(Index As Integer, Optional bCountConnected As Boolean = True)On Error GoTo EH        'Remove user        Dim iCtr As Integer, iCount As Integer        Dim iCompanyID As Integer        Dim sUserNickName As String        Dim sOnlineUsers As String        Dim bSupportGuy As Boolean        Dim bFound As Boolean                 iCount = lvwUsers.ListItems.Count        For iCtr = 1 To iCount             DoEvents             If Index = CInt(lvwUsers.ListItems(iCtr).Text) Then                 bFound = True                 sUserNickName = lvwUsers.ListItems(iCtr).ListSubItems(1).Text                 iCompanyID = lvwUsers.ListItems(iCtr).ListSubItems(4).Text                 If lvwUsers.ListItems(iCtr).ListSubItems(5).Text = "TRUE" Then bSupportGuy = True                Exit For            End If        Next        If bFound = True Then            tmrUsers(Index).Tag = ""            tmrUsers(Index).Enabled = False            Winsock(Index).Close            lvwUsers.ListItems.Remove iCtr            '            'inform all about disconnected user            Dim bIsSupportAvailable As Boolean            GetOnlineUsers iCompanyID, sOnlineUsers, False, sUserNickName, bIsSupportAvailable            If Len(Trim(sOnlineUsers)) > 0 Then                Inform2RelatedUsers sOnlineUsers, SCK_CODE_DISCONNECTED & Index & "|" & _                    sUserNickName & EndTag(SCK_CODE_DISCONNECTED)            End If            If bSupportGuy = True Then                If bIsSupportAvailable = False Then                    SendMessageToAll SCK_CODE_SUPPORT_AVAILABLE & bIsSupportAvailable & _                        EndTag(SCK_CODE_SUPPORT_AVAILABLE)                End If            End If            If bCountConnected = True Then GetConnectedSockets        End If        Exit SubEH:        ErrorLog "Procedure name : frmMain.Close_Socket"End Sub  Private Sub ConnectionRequest(Index As Integer, ByVal requestID As Long)    On Error GoTo EH        Dim iConnection As Integer         iConnection = GetFreeConnection        If iConnection = -1 Then            'no free conection, load a new winsock            Load Winsock(Winsock.UBound + 1)            Winsock(Winsock.UBound).LocalPort = PORT            iConnection = Winsock.UBound        End If         Load tmrUsers(iConnection)        tmrUsers(iConnection).Tag = ""        tmrUsers(iConnection).Interval = 20000        tmrUsers(iConnection).Enabled = True                ' accept the incoming connection on our new control        Winsock(iConnection).Accept requestID        GetConnectedSockets        Exit SubEH:        If Err.Number = 360 Then Resume Next 'tmrUsers(iConnection) Object already loaded        ErrorLog "Procedure name : frmMain.ConnectionRequest"End Sub  Private Function GetFreeConnection() As Integer    On Error GoTo EH         Dim iConn As Integer, iCtr As Integer, iCount As Integer                 iConn = -1        iCount = Winsock.Count - 1        For iCtr = 1 To iCount            DoEvents            If Winsock(iCtr).State = 9 Then                Close_Socket iCtr, False                iConn = iCtr                Exit For            ElseIf Winsock(iCtr).State = 8 Then                Close_Socket iCtr, False                iConn = iCtr                Exit For            ElseIf Winsock(iCtr).State = 0 Then                iConn = iCtr                Exit For            End If        Next        GetFreeConnection = iConn        GetConnectedSockets        Exit FunctionEH:        ErrorLog "Procedure name : frmMain.GetFreeConnection"End Function  Private Function GetConnectedSockets()    Dim iConn As Integer, iCtr As Integer, iCount As Integer        iCount = Winsock.Count - 1    For iCtr = 1 To iCount        DoEvents        If Winsock(iCtr).State = sckConnected Then            iConn = iConn + 1        End If    Next    lblUserCount.Caption = iConnEnd Function

Peer-to-peer Connection Help!
Hi,

How can I establish a peer-to-peer connection with another computer that may be miles away?? Do I use the winsock control? Also, is it possible to connect to another computer to chat without letting the other person know your IP address?? And is there a way to download a file off another persons computer automatically once the two computers are connected and by knowing the file path????

Thanks in advance

Peer To Peer Connection
I have a Peer to Peer Conection
I want it to when i try to connect with Peer A
Peer B will automaticaly Let it Connect
How can i do this
?

How To Get The State Of Individual Line,high Or Low?
Would you please tell me how to detect the states of individual pins on RS232 using VB?
Thanks a lot

Winsock Connection...
ok, im trying 2 make a little instant messenger sorta program, anyways, i have it set up with a radio button so that u either choose to accept messages (server) or send (client). When u press accept and click connect it should just set the local port on winsock1 to whatever the text box for local port is (1412 is what im using). when u press send messages and press connect, it should connect to the ip u entered using the port u entered (127.0.0.1, and 1412). Ok, now, if i make it an exe, open it twice, and set one to be the server and the other to be the client, and presss connect on both, the state of the server side is 0, and the client side goes from state 6 to state 9 (im not sure what these 2 are, but i know 7 is connected). I cant get it to connect to the other program thats open, ill post my code below... and also, if i set the local port on the winsock to port 1412 and connect to port 1412 the program works fine (im doing this without opening the program twice). and i can send messages and all, however it needs to work if some1 were to open the program on different computers. im just gonna post my code for the main form, since the other 2 just tell it to send messages (which work fine if its connected). Hopefully some1 will b able 2 help me out!


Code:
'Declare Variables
Public blnListening As Boolean
Public strMessageTaken As String
Public blnReady As Boolean

'Connect
Private Sub cmdConnect_Click()
If blnListening = True Then
Winsock1.LocalPort = txtLocalPort.Text
frmServer.Show
cmdConnect.Enabled = False
Option1.Enabled = False
Option2.Enabled = False
txtLocalPort.Enabled = False
txtName.Enabled = False
blnReady = True
End If
If blnListening = False Then
Winsock1.LocalPort = "0"
frmClient.Show
cmdConnect.Enabled = False
Option1.Enabled = False
Option2.Enabled = False
txtIP.Enabled = False
txtPort.Enabled = False
txtName.Enabled = False
Winsock1.Connect txtIP.Text, txtPort.Text
blnReady = True
End If
End Sub

'Close Connection
Private Sub Close_Click()
Winsock1.Close
frmClient.Hide
frmServer.Hide
cmdConnect.Enabled = True
Option1.Enabled = True
Option2.Enabled = True
txtIP.Enabled = True
txtPort.Enabled = True
txtLocalPort.Enabled = True
txtName.Enabled = False
blnReady = False
End Sub

'Load Form
Private Sub Form_Load()
Winsock1.Close
If Option2.Value = True Then
blnListening = False
Else
blnListening = True
End If
txtName.Text = Winsock1.LocalHostName
End Sub

'Exit
Private Sub Label8_Click()
Unload frmClient
Unload frmServer
Unload frmConnection
End Sub

'Listening Options:
'xxxxxxxxxx
Private Sub Option1_Click()
If Option2.Value = True Then
blnListening = False
Else
blnListening = True
End If
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
blnListening = False
Else
blnListening = True
End If
End Sub
'xxxxxxxxxx

'Peridoc1
Private Sub Timer1_Timer()
frmConnection.Caption = "Connection: " + LTrim$(Winsock1.State)
lblYourIP.Caption = RTrim$("Your IP: ") + Winsock1.LocalIP
End Sub

'Connection Request
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If blnReady = True Then
Winsock1.Accept requestID
Winsock1.Listen
If Winsock1.State = 7 Then
frmServer!rtbMessages.Text = "Connected!"
frmClient!rtbMessages.Text = "Connected!"
End If
End If
End Sub

'Receive Data
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
If blnListening = True Then
Winsock1.GetData strMessageTaken
frmServer!rtbMessages.Text = frmServer!rtbMessages.Text + strMessageTaken
End If
If blnListening = False Then
Winsock1.GetData strMessageTaken
frmClient!rtbMessages.Text = frmClient!rtbMessages.Text + strMessageTaken
End If
End Sub

Winsock TCP Connection
I need to write a little program to send Unix/linux command to a remote PC by LAN connection. I do it now by Hiperterminal and it works fine. I want to write a program to have help in this way:
in Unix/linux if I send ps -e they show me the list of the active process, if i send cd they change directory and so on..............
Now I want to log in and by pressing some botton in the main panel of my program I want to send the command.
I use the winsock and this code:
Private Sub Command1_Click()
Winsock1.Protocol = sckTCPProtocol
Winsock1.Connect Text2, Text3
End Sub

Private Sub Command2_Click()
Winsock1.Close
End Sub

Private Sub Command3_Click()
Winsock1.SendData Text4 & vbCrLf
End Sub

Private Sub Form_Load()
Dim Instringa As String
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData Instringa, vbString
Text1 = Text1 & Instringa
End Sub

Private Sub Winsock1_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)
MsgBox "ERRORE : " & Description
Winsock1.Close
End Sub
When I press connect (port number 23=telnet)I see in the text1 some characters unknow like this:
ÿýÿý ÿý#ÿý'
If I change the port (21=FTP) I see the welcome message. When I use telnet by hyperterminal (by TCP Winsock on port 21)I don't have this problem......How I can translate it?
I'm sorry for my bad english .Thanks!!!

Winsock Connection Que?
Can someone give me an example of how I would make a client-server program, that the client is in a que and has to wait until its his turn?

Winsock Connection Help
i just get an overflow...

nvm i got it.

right now with this...




VB Code:
Private Sub Command1_Click()Dim x(3) As Datax(0) = &H4x(1) = &H0x(2) = &H89x(3) = &HCWinsock1.SendData (x)End Sub


this worked last time i tryed..now it wont work im sending data as u can see im sending it as HEX

and i get an error..

and... i need to connect to the server and a client..the server connect's but..the client dont for some reson..



VB Code:
Private Sub Form1_load()winsock1.remotehost = "gsproduc.ath.cx"winsock1.remoteport = 9100winsock1.connectwinsock2.remotehost = "127.0.0.1"winsock2.remoteport = 9100winsock2.connectEnd Sub


that isnt the code i have im using the simple part in the winsock control the custom thing...anyways the code i put there is just 2 tell u what i would have if i was putting it in if u get me. ok now the server connect's but the client dont...(if u must know im sending packets to a game server) this all worked out b4 i had 2 formatt my pc so if anyone can help thx alot

-infamouszero-

Winsock Connection
i'm working on networked computers and trying to connect to the computer beside mine using winsock. when my program starts my state will get to 6 (connecting) but never to 7. no matter how many times i loop through the process i can't make a connection! does anyone know why?

UDP Connection With Winsock
problem with udp, when i make a winsock control and i tell it to use the udp protocol it doesn't work. I've read the F1 help file many times over on the winsock control it might have an error or two on it. I can make a tcp/ip connection fine, but I want the ability to make a udp connection. here is the code if you can find anything to improve or help me, then I would be thankfull


Server side code:

Private Sub Form_Load()
Winsock1.LocalPort = 2020
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim incomedata As String
Winsock1.GetData incomedata, vbString
Label2.Caption = incomedata
End Sub

Client based code:

Private Sub Command1_Click()
Winsock1.SendData ("testing")
End Sub

Private Sub Form_Load()
Winsock1.RemotePort = 2020
Winsock1.RemoteHost = "192.168.1.2"
End Sub

Winsock Connection
winsock connection does not re-establish for 5minutes atleast after the connection has broken. this is sometihng i really dont want in my vb chat .


any suggestions ?

Winsock Connection
I am trying to create a client/server application with the client side having multiple forms. I am trying to establish a winsock connection and remain connected throughout all forms until the user logs off however i cannot establish the connection in the first place . I thought about using modules however i am unsure how to create a winsock connection using this method.
This is the code i am using at the moment in the client side;

[VB]
Private Sub Form_Load()
lblip.Caption = WS.LocalIP
WS.RemoteHost = "ipaddress"
WS.RemotePort = 1001
End Sub

Private Sub cmdconnect_Click()
WS.connect
End Sub

[/VB]

this code however does not allow a connection
Any suggestions on how this could be acheived would be most welcome.

Winsock Connection
Can any1 see why my winsock won't connect =)...(Doesn't make it to DataArrival Sub), prolly something stupid, but yeah, Can't see it :P


Globals.

Code:

Dim lstLoaded As New clsLB
Dim lstFound As New clsLB
Dim ID(1 To 60) As String





Start

Code:

Private Sub cmdStart_Click()

Dim i As Integer

If lstLoaded.ListCount < 1 Then
Exit Sub
ElseIf lstLoaded.ListIndex = lstLoaded.ListCount - 1 Then
Exit Sub
End If

Call RotateUsers(lstLoaded, lblCountLoaded)

For i = 1 To cmbSockets.Text

ID(i) = txtBefore.Text & lstLoaded.Text & txtAfter.Text
Winsock(i).Close
Winsock(i).RemoteHost = "profiles.yahoo.com"
Winsock(i).RemotePort = 80
Winsock(i).Connect
Call RotateUsers(lstLoaded, lblCountLoaded)


Next i
txtStatus.Text = "Connecting..."

End Sub





Connect

Code:

Private Sub Winsock_Connect(Index As Integer)

Dim Packet As String

Let Packet = "GET http://profiles.yahoo.com/" & ID(Index) & "HTTP/1.0" & vbCrLf
Let Packet = Packet & "Connection: Close" & vbCrLf
Let Packet = Packet & "Accept: */*" & vbCrLf & vbCrLf

txtStatus.Text = ID(Index)

Winsock(Index).SendData Packet

End Sub

Winsock And IRC Connection
Ok you're all probably getting sick of my posting about problems with my IRC client I'm coding in VB6. I'm getting it to connect to the IRC server, its getting the following messages back:

Quote:
Connected to irc.hackthissite.org...

:irc.hackthissite.org NOTICE AUTH :*** Looking up your hostname...
:irc.hackthissite.org NOTICE AUTH :*** Found your hostname

This is all fine and good. What it does is connect to the server, uses the winsock.getdata function to grab the incoming data from their server and then prints it to my multiline chat textbox. After the "Found your hostname" line, usually (when I use telnet) I can type in "user username 127.0.0.1 localhost :realname", hit enter, type "nick username", hit enter, and then "pass *" and hit enter and it replys with all sorts of good messages, and from there I can join channels and chat and stuff. however, in my vb6 client, when I try to send the first "user username 127.0.0.1 localhost :realname" command it either isn't sending it or it just isn't working. I've added code to check the connection state (equals 7) before sending this line.
what happens is it hits the winsock.senddata line, and then I have it check for incoming data using the winsock.getdata line, which is in a loop for awhile until it gets data. but its not getting any data.
I also have a timer set which every 1000 miliseconds, checks for PING's in the incoming data buffer lines and also prints any incoming data to the screen. It doesn't appear to be seeing any incoming data either.
so basically, after the above output, my progam just sits there, connected, but not doing anything. if someone could help me with how exactly I send data and check that it sent properly, that would be great.
I know I have to check for pings and reply with pongs for my connection to stay up. what I'm not sure of is if I need to use a second winsock control which listens on the Ident port, listening for IdentD packets. This could be part of the problem, but I'd like to know if anyone else has tried writing their own IRC client using VB6 at all. does anyone know the raw transactions that occur between client and server during an IRC server connection/identification?? I'm not very knowledgeable on the Ident stuff, all I know is that the IRC server checks on like port 113 or something (Ident port) to make sure my hostname is correct. Maybe I need this, I'm just not sure.
Any help would be great, even if you only want to crap out your 2 cents worth on the idea.




Edited by - wagnj1 on 8/27/2004 7:37:18 AM

WINSOCK Connection
How do i set up winsock so it connects to the msn server.

Copyright © 2005-08 www.BigResource.com, All rights reserved