Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

winsock
I'm using winsock control in VB 6 to write a an application so that the
client can send string to the server and receive a string back from the
server indicating the status.

The client is a scheduled task.  When it runs, it will get a recordset and
send each record as a string to the server.  For each string the server
receives, it will send a string back to the client.  Upon receiving this
confirmation, the client will continue sending records.  This sending proces
s
needs to be automated.

I can't get it work.  The DataArival event of the winsock in the client
application didn't file until the who app ends.  What I want on the client
side is Send, Receive, Send, Receive, ....

Can someone help please.  I've been struggling for a few days now.  Please
let me know if more detail is needed.  Thanks.


Report this thread to moderator Post Follow-up to this message
Old Post
li
10-29-04 08:55 PM


Re: winsock
"li" <li@discussions.microsoft.com> wrote in message news:4F76A624-531A-
4D82-9438-2D8813BE5ECB@microsoft.com
> I'm using winsock control in VB 6 to write a an application so that
> the client can send string to the server and receive a string back
> from the server indicating the status.

This is a *very* simple sample that may get you started.

Project 1: client: form with 1 winsock control and 1 command button

Private msData As String

Private Sub Command1_Click()
Dim ff As Long
' get some sample data to send
ff = FreeFile
Open "C:\winnt\system32\drivers\etc\hosts" For Binary As #1
msData = Space$(LOF(ff))
Get #ff, , msData
Close #ff
' connect to server
With Winsock1
.Protocol = sckTCPProtocol
.RemoteHost = "127.0.0.1"
.RemotePort = 99
.Connect
End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Winsock1.Close
End Sub

Private Sub Winsock1_Connect()
SendNextLine
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sBuff As String
Winsock1.GetData sBuff
Debug.Print "server response: " & sBuff
SendNextLine
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 "winsock error " & Description
Unload Me
End Sub

Private Sub SendNextLine()
Dim sLine As String
Dim x As Long
x = InStr(1, msData, vbCrLf)
If x Then
sLine = Left$(msData, x + 2)
msData = Mid$(msData, x + 2)
Else
sLine = msData
End If
If Len(sLine) > 0 Then
Winsock1.SendData sLine
Else
Unload Me
End If
End Sub

--------------------------------------------------------
project 2: form with 2 winsock controls

Private Sub Form_Load()
' configure listener
With Winsock1
.Protocol = sckTCPProtocol
.LocalPort = 99
.Listen
End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Winsock2.Close
Winsock1.Close
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock2.Accept requestID
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 "winsock1 error " & Description
Unload Me
End Sub

Private Sub Winsock2_Close()
Debug.Print "EOF"
Winsock2.Close
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Static sBuff As String
Dim sData As String
Dim x As Long
' buffer incoming data looking for vbCRLF delimiter
Winsock2.GetData sData
sBuff = sBuff & sData
x = InStr(1, sBuff, vbCrLf)
If x Then
' we have a record
sData = Left$(sBuff, x + 2)
sBuff = Mid$(sBuff, x + 2)
ProcessRecord sData
End If
End Sub

Private Sub Winsock2_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 "winsock2 error " & Description
Unload Me
End Sub

Private Sub ProcessRecord(ByVal TheData As String)
Debug.Print "got " & TheData
Winsock2.SendData "X" ' ack client
End Sub

---------------------------------------------------------
edit the client code to open an existing text file if the hosts file isn't
found; run the server and then run the client and click the command button.
the server will accept 1 line at a time and send back a single byte to
acknowledge that it is ready for the next record.


--
Reply to the group so all can participate
VB.Net... just say "No"


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
10-29-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:08 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.