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




Winsock Array DataArrival


I was wondering if on a winsock array DataArrival event if this is this is the correct way to recive the data for the active control?


VB Code:
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)Dim data As StringWinsock1(Index).GetData dataEnd Sub


Thanks,
Jason




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Winsock DataArrival
I have a Winsock control on one form. I create an instance of it on another form like this:


VB Code:
Private WithEvents Socket as Winsock Private Sub Form_Load()Set Socket frmHandle.SocketEnd Sub


Now basically to my understanding what is happening here is the pointer from the control on the original form is being set to the Socket on the other form. Now u can basically use that control via the instance that was created on the other form.

Now when data arrives via the data arrival event, according to me, 2 events would fire, one in the control holder form and the other one in the instance holder form, right? If not then will the event in the instance holder form or the control holder form will fire? But if yes, then if VB stacks up events in a queue, one event in the control holder form will be launched and then the second one in the instance holder form, right (or is it vice versa)? But if VB handles events simultaneously, then both the events in the control holder form and the instance holder form will execute simultaneously, right? Hoping someone will shed some light on how this works.

Thanks

Winsock DataArrival
I am trying write a client that sends a UDP packet to the server. The packet should contain a byte field, integer field, boolean field, and a string field. I think a bytearray is the way to go because the java server accepts a bytearray as part of its datagramPacket, but I'm not sure how to pack the byte array containing these fields. Is the bytearray the best way to go about sending the packet? If so, how? If not, what other construct should I use to send the packet with the desired fields?

Winsock DataArrival
I am using a winsock control, set to UDP. When I recieve data using the GetData event, can I receive a bytearray and then from that byte array -- pull out the items such as an int, bool, string... if so, how do I do that using vb.

Thanks.

Winsock... Waiting For DataArrival
Hello There...

I have a winsock control connected to a newsserver.

I want to send a command, wait for the response, send another command, and so forth. But what is the most effective way to do this?


Code:
Private Sub SendNNTPCommand(NNTPcom As String)
ResponseReveived = False
Call Winsock.SendData(NNTPcom)
End Sub

Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Call Winsock.GetData(CmdResponse)
ResponseReceived = True
End Sub

Call SendNNTPCommand("AUTHINFO user " & username)
'Here I want to wait for the response, before sending the next command.
'It could be done using sleep or timer... but what is the best way to do it?
Call SendNNTPCommand("AUTHINFO pass " & password)
Thanks

Winsock - DataArrival && SendData
I'm working on a client/server IM program. I have 3 textboxes in array. I want to send the data from those 3 textboxes to the other IM which has those same 3 textboxes in same array. After trying something out, I got it to be able to receive data and put it in the correct textbox by adding a static counter. However, it seems that the SEND is only sending once. Shouldn't it be sending 3 times because of the loop, therefore, the RECEIVE should be getting data at 3 different times? Here's the code for the DataArrival:


vb Code:
Static x As IntegerDim a(1 to 3) As String x = x + 1 Winsock.GetData a(x)Text1(x).Text = a(x) If x = 3 Then x = 0


Technically, it should get the 1st piece of data received and put it in text1(1). When it gets the next piece of data, it should put it in text1(2). However, the SEND seems to be sending it once and all data from text1(1-3) from sending program is being put in text1(1) of receiving program. When I click SEND again, the same thing will happen but the receiving program will put it in text(2). Why is the send not sending the data at 3 different times if the for/next is telling it to sendData 3 times?

Code for SEND:


VB Code:
Dim x As Integer, a(1 To 3) As String For x = 1 To 3a(x) = Text1(x).TextWinsock.SendData a(x)Next x

Problem With Winsock DataArrival
Hi , Im having an issue reading from winsock

here is the code i currently have

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim X As String

Winsock1.GetData X, vbString

End If
If InStr(1, X, "> Login:") Then
MsgBox "G3"


End Sub

the problem is the data sometimes comes as
> Login:

and some times comes as
>
Login:
how can i fix it and read the correct way without using
If InStr(1, X, "Login:") Then
because it will give me errors, is there any way i can force it to read the whole incoming data before trying the If statement?


Thank you!

Winsock DataArrival Problem
Hi everyone,

My program is not working properly and I think the most likely solution is due to the fact that it is starting a function that involves the Data received, which I think hasn't been received yet.

So in other words its trying to use something that isn't complete.

Is there a way to wait for the Data to be fully sent.

Hopefully that is the problem.

Edit:


VB Code:
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)     Dim strResponse As String    Dim rs As String    Dim upperbound As Integer    upperbound = UBound(myArray())    Dim rsArray(0 To 5) As String    Dim i As Integer     winsock.GetData strResponse, vbString, bytesTotal     strResponse = FormatLineEndings(strResponse)        ' we append this to the response box becuase data arrives    ' in multiple packets    txtResponse.Text = txtResponse.Text & strResponse           rsArray(loopnumber) = Decrypt(txtResponse.Text)  If loopnumber >= UBound(myArray) Then  Label1.Caption = "Status: Links Decrypted"  For i = LBound(myArray) To UBound(myArray)  Label4.Caption = Label4.Caption & rsArray(i) & vbCrLf  Next  Else  loopnumber = loopnumber + 1  Timer1.Enabled = True  Timer1.Interval = 1  End If


^^ That is my Sub for DataArrival

Thanks for all help given.

Question On Winsock DataArrival
When the DataArrival event fires. If I didn't get the data, does it stay in the receive buffer?

I'm asking because I noticed that if I send over 8192 bytes of data, mutiple DataArrival Events fire, each 8192 bytes in size. I'm trying to decide whether I wait for all DataArrivals (concatenating everyting, SendComplete will send a packet for end concatenate/start processing) assuming the data stays in the receive buffer if I only Peek but not Get (my initial question), or if I'll Get and assemble the data in some other way.

DataArrival Event / Winsock
I am having problems with the dataArrival event on the server side of a winsock connection.

I have a loop on the client side, sending an byte array of 4096 bytes at a fairly constant rate.

My problem is that after a random number of calls to the dataArrival event by the server, it is not receiving all of the data. For example after 10 loops on the client side (sending data), the dataArrival will be called after only receiving half of the data.

Anyone know about this problem?? Or when dataArrival is supposed to be called (ie. When the first bit of data arrives, all the data, half way...)??

I've been stuck on this bug for 3 days. I need help!!

Thanks!

Winsock DataArrival Event
Hi All,  I am having a little problem with winsock and I hope someone can help me out.

I am using UDP Protocol and want to simulate a SEND/Ack mechanism.

I have a form with a button on it.  When I click the button, I attempt to send my data.  The receiving end returns an "Ack".

Also, I have implemented a Timeout feature and a Max Retry feature whereby if the Ack is not received within the Timeout, I re-send up to the number of Retry count allowed.

Here is some code...in a nutshell

Private Sub c_Socket_DataArrival(ByVal bytesTotal As Long)
   Dim bytes() As Byte
   Socket.GetData bytes
   boolAckReceived = True
End Sub

Private Sub ButtonClick()
   Dim SendTime as long
   Dim TestInterval as long
   dim TimeDiff as long

   SendTime = SendData(b, RetryCount)
   Do While Not boolAckReceived And RetryCount < 4
      TestInterval = Timer() * 1000   'msecs
      TimeDiff = TestInterval - SendTime
      If TimeDiff >= 250 Then
         RetryCount = RetryCount + 1
         SendTime = SendData(b, RetryCount)
      End If
   Loop
End Sub

Private Function SendData() As Long
    Socket.SendData ("my data")
    SendData = Timer() * 1000
End Function

Everything works great in most cases...except when it falls into the retry loop.

What happens is that all the "re-sends" are sent and then all the "ack" are received.  It seems that the DataArrival event does not get fired until ALL the retry have been sent. ie the While loop is complete.  

I can put in a DoEvents in the code but then the button frees and I am able to click again.  It is important to maintain the completion of the retries until an ack is received.  

How do I get the DataArrival event to trigger or register during the loop ????????

Thanks.




Winsock DataArrival Event
I have a built a port listener that is a VB exe, then I have a client that is a VB Dll that will be called from an ASP page. I will be passing files, anything from a plain text file to an mp3 file. I am having trouble saving data over 8k on the listener because of the mutliple calls to the data arrival event. I know I need to write the file and then append to it with each subsequent call to data arrival event. I tried using code from the microsoft knowledge base http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q275004 but the file gets corrupted and the code is for Embedded Visual Basic.

Here is the code used to prepare the file in the dll to be transfered thru the socket

-----------------------------
Public Function SendBinaryData(ByVal sFileName As String) As Boolean
    Dim lOffset As Long
    Dim bTemp As Byte
    Dim bFileData() As Byte
    Dim lLength As Long
    Dim WSAResult As Long
    
    Open sFileName For Binary Access Read As #1
    ReDim bFileData(FileLen(sFileName))
    lLength = FileLen(sFileName) + 1
    
    For lOffset = 1 To lLength
        If Not lOffset = lLength Then
            Get #1, lOffset, bTemp
            bFileData(lOffset - 1) = bTemp
        Else
            bFileData(lOffset - 1) = CByte(26)
        End If
    Next lOffset
    
    Close #1

    WSAResult = send(mlngSocket, bFileData(0), lLength, 0)
    If WSAResult = SOCKET_ERROR Then
        SetLastErrorCode "Error en SendData::send"
        SendBinaryData = False
    Else
        SendBinaryData = True
    End If
    
End Function
    
----------------------

Here is the code I use in the data arrival event to save the file, this works for anything under 8k. If it is over 8k multiple calls to the data arrival event are called and only the last packet of data sent is saved.
------------------------------------
Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim sItemData As Variant
    Dim strConnect As String
    Dim i As Long
   
        
    ' get data from client
    Socket(Index).GetData sItemData, vbByte + vbArray

    'Create FileSytemObject Component
    Dim ScriptObject As Scripting.FileSystemObject
    Set ScriptObject = New Scripting.FileSystemObject

    'Create and Write to a File
    Dim MyFile As Scripting.TextStream
    Set MyFile = ScriptObject.CreateTextFile("c: cpipinary.txt") 'filename is hardcoded for testing

    For i = 1 To LenB(sItemData)
        MyFile.Write Chr(AscB(MidB(sItemData, i, 1)))
    Next

    MyFile.Close
    Set MyFile = Nothing

    'Send response back to client
    Socket(Index).SendData ("Binary File created on host computer " & Now())
End Sub
-----------------------------------

Winsock DataArrival Gives No Headers
i don't understand this but i've done some searching and found a few tutorials and stuff on Winsock (like this one: http://www.vbip.com/winsock/winsock_http_02.asp), and all of em claim that the headers are returned in the DataArrival event, yet i never receive any.

my code in the DataArrival function is simply:
wscHttp.GetData strData
m_strHttpResponse = m_strHttpResponse & strData

all i get is the HTML code..... what's the deal?


edit: nm, i fixed it...

DataArrival Winsock Event.
Can someone help me troubleshoot this? I dont understand why the DataArrival event is not automatically fired in the following code. I am pretty new to VB so I may be missing something silly, but I am stuck nonetheless. I have verified that there is data waiting there, so why does the method not fire? Any ideas?


Module1 Code

Public Sub Main()

Dim Test As Class1
Set Test = New Class1
Test.Connect


End Sub

and a class module that looks like

Public WithEvents tcpClient As MSWinsockLib.Winsock
Public Sub Connect()

Set tcpClient = New MSWinsockLib.Winsock
tcpClient.Protocol = sckTCPProtocol
tcpClient.Connect "localhost", 23
Debug.Print tcpClient.State
End Sub

Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Debug.Print "here"
End Sub


After some reseach it doesnt look like any event is firing.... I am so stuckkkkk....

Winsock DataArrival Error
I have created the following VB app using winsock controls. I want to execute a korn shell script I created that sits on a Solaris 8 server. I connect ok but for some reason my unix program is not executed, in my debug statement I get the following returned "#'$". I think it might be a timing issue but can't get my head arund it. I get the same when I try to issue simple ls or whoami commands using winsock send data

Can anyone help?


Private Sub Form_Load()
tcpClient.RemoteHost = "myunixmachine"
tcpClient.RemotePort = 23
End Sub

Private Sub cmdConnect_Click()
' Invoke the Connect method to initiate a
' connection.
tcpClient.Connect "myunixmachine", 23
End Sub

Private Sub tcpClient_connect()
Debug.Print "connect to unix system"
'Logon process
tcpClient.SendData uid & vbCrLf
tcpClient.SendData password & vbCrLf
Debug.Print tcpClient.State
End Sub

Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
tcpClient.GetData strData
txtOutput.Text = strData
Debug.Print strData

End Sub

Private Sub Command1_Click()
Dim str As String
unixcommand = myunixprog
tcpClient.SendData (unixcommand & vbCrLf)
Debug.Print "got here"
Debug.Print tcpClient.State
End Sub

WinSock DataArrival Problem
Dear all,

I am trying write a client that receive a TCP packet from the server. The packet should contain a byte field, integer field, boolean field, and a string field. I have defined different types of variables within the Type structure.
I'm not sure how to pack the packet and store in the variables that I defined. Is the bytearray the best way to go about sending the packet? If so, how? If not, what other construct should I use to receive the packet with the desired fields?

Regards,

Winsock, Dataarrival, Whats The Ip From The Sender?
Hi all,

I have list with ip's, and i want ot send them a message. They respond, but here comes the problem. Not every response returns the ip address. How can i see what ip address sended me the recieved data? Is there a function or procedure for?

many thx if you can help me

wous

Winsock DataArrival And String Concatenation
Hi, I made a Usenet binary reader that downloads with several simultaneous connections. If a file is split in 250kB segments, the CPU usage gets to 30%, but when a file is split in 800kB segments the CPU usage gets to 90%.

The problem is the string concatenation on this line:
TotalData(Index) = TotalData(Index) & Data(Index)

The more data gets added to TotalData(Index), the higher the CPU usage gets.

Is there a better way of joining the incoming data, so the CPU usage won't be so high with bigger segments?



vb Code:
Private Data(0 To 9) As StringPrivate TotalData(0 To 9) As String Private Sub Winsock_DataArrival(Index As Integer, ByVal bytesTotal As Long)   Winsock(Index).GetData Data(Index), vbString 'Receive data   TotalData(Index) = TotalData(Index) & Data(Index) 'Join data   'If entire segment has been downloaded  If InStr(Data(Index), vbNewLine & "." & vbNewLine) Then   Decode TotalData(Index) 'Decode data  TotalData(Index) = vbNullString   NextSegment(Index)  End If

Winsock DataArrival Does Not Fire As Expected
This is the problem:

During certain circumstances, I know two specific ones, the DataArrival event does not fire. Consequently, I can not write my application safe, i.e., I need the incoming data to continue, but since the DataArrival event does not fire the application "hangs". The data actually comes in and up to the TCP layer, the problem is related to the VB event.

The two situations that I know of when this problem arises are:

1. Using VB6 menus.
2. Holding the window (form) using the mouse, e.g., when you move a window (form).

The DataArrival event fires when you release the menu or the window.

My guess is that it is some pointer problem using the underlying dll.

Can anyone help me solve this problem? My current solution is to NOT use menus and to NOT let the user move the window. Not good...

Thanks.

/Magnus

Winsock DataArrival Event Not Firing
My aim is to be able to share an open winsock connection through multiple forms.
To do this I have the MSWINSCK.OCX is loaded as a reference in my project rather than adding in the control on separate forms. I’ll come back to this approach later on.
I have a module in which I have the following declaration :
   Public Winsock1 As Winsock
This enables recognition of ‘Winsock1.’ as the object identifier throughout all of the forms on the project.

Now to the code on the form.

Private Sub Form_Load()
    Set Winsock1 = New MSWinsockLib.Winsock
End Sub

Private Sub cmdConnect_Click()
    Winsock1.RemoteHost = "172.16.96.238"
    Winsock1.RemotePort = 8104
    Winsock1.Connect
End Sub

Private Sub cmdStatus_Click()
    MsgBox Winsock1.State
End Sub

Private Sub cmdClose_Click()
    Winsock1.Close
End Sub

Private Sub cmdSend_Click()
    Winsock1.SendData txtSend & vbCrLf
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData recv, vbString
    MsgBox recv
End Sub

I have a session looking at what happens on the port on the server – this is connected through a separate bit of terminal emulation software and looking at port 104 through the server itself. (MvBase 1.3 platform incidentally).

On Connect button works – the Status button click will now show a state of 7 (Connected).
I can key in the text to send to the server (as in the account to log in to), click the Send button and see on my session monitor that a log in is made on the port. I can key in other commands and send them to the server as well – all being transmitted through to it without any problem and producing a response that I can see on the session monitor.
But the DataArrival event doesn’t fire. This is the problem.

If I get rid of the reference and add the winsock control directly on the form, the event fires as it should.
This doesn’t allow me to keep the winsock communication going when moving between forms on a project.
Is this a problem with using the MSWINSCK.OCX as a reference, or is there more I need to do to get the events to work?

As an alternative, I have tried applying the winsock control 2 forms – setting both up to have the same winsock connection parameters. The 1st form will open the connection and will report a status of 7, but when I get it to load the 2nd form and check the status on that, it reports the connection as closed. I don’t think this is the way forward.

Any assistance would be appreciated.
This is only my 2nd week of application development in VB6, so apologies in case I have missed out something obvious.
Actually I hope it IS something silly I've missed.

Many thanks.
MrSlow.

Winsock DataArrival Parsing Question
Hi,

I'm trying to through parse the full webpage source code after I use the winsock GET method to load the webpage.

The problem is, Winsock loads the data in chunks, and a lot of times the string that I'm parsing for doesn't exist.

Is there any way to get wait until Winsock has downloaded the full page?

Winsock - How To Detect If DataArrival Event Is Not Triggered?
Hello,

I have a network monitor app that i am creating in VB6. I want to be able to detect if a connection is NOT made, and then call a subroutine based on that. If the connection is good, then I want to ignore it, and loop to the next socket to poll for a service.

The problem that I am faced with, is that I can not figure out how to get an event or create a function that will return if the socket does NOT connect..... Only if it does....


I tried to use the Winsock1_Connect function, however, it still returns true even if there is no server on my LAN with the specified address!

If anyone has any advice, it would be greatly appreciated... Thanks!

[Winsock] Dataarrival Event Still Fired After A Close
Hi,

I am new to winsock programming and I have some strange behaviors that I can't figure out.

When I am downloading large files (up to 1MB), this problem occurs: The dataarival is still fired after having the close event fired... even if I do a "winsock.close" in the close event sub

The strange thing is, all packets I receive after the close are empty but the bytestotal is not null... When finally the dataarival is not fired anymore I can have received up to 5 times more data then my filesize is!
But my file is well downloaded, I write it to disk in the close event sub after having closed the winsock and the file is just complete, when I download an .exe file I can run it without problem, no byte is missing.

I usually perform some researchs before asking something in a technical forum but for this problem I haven't found anything.
I know there is a known similar bug recensed by microsoft:
http://support.microsoft.com/?scid=k...9692&x=20&y=14

But this is not my problem because in one hand I have the VB SP6 installed (that correct the bug) and on the other hand I dont have the following symptom related to this bug:


Quote:




A Winsock control may fire a DataArrival event with valid data length (a number that is greater than 0) after the Close event. If you try to call the GetData method for that event, you receive the following error message:
Run-time error: 40006

Wrong protocol or connection state for the requested transaction or request.




Any help would be greatly apprecied

Thanks

Tom.

How To Wait For A Specific Value In The DataArrival Evant In Winsock?
How can I wait until winsock gets a value, and check if it is a value I want?

Winsock Control DataArrival Event Method
Hi,

i create a winsock control dynamically, when a connect request comes in:

aNewSock = New AxMSWinsockLib.AxWinsock()
aNewSock.CreateControl()

aNewSock.Accept(e.requestID)

how can i define a DataArrival-Method fr aNewSock ?
Is Invoke the right method to define a callback function ?

thanks for help

Winsock Stops Throwing Dataarrival Events?
Hi,

I have a VB6 project that uses a winsock control to receive text
messages over a UDP connection.

It used to work fine. However, when I changed the code to make it more
efficient (ie, less processing was done with each received message), the
program has this weird bug where it will stop acting on the messages
received. The program might work fine for a whole day, receiving
thousands of messages, so it is an intermittent problem.

When it does stop responding, the program itself is still responsive to
user inputs, and a log file I wrote indicated that no new messages were
being received. However, if the program is stopped and restarted, the
messages are again processed.

Another winsock control that is listening on port 80 for web requests
also continues to work.

Has anyone encountered this or know of a possible solution?

Winsock Control: DataArrival Fires B4 Connect Event
I have a class module that traps the events of a Winsock control. I am using the class module to send email messages.

I have a custom initializatin routine that I can call from outside the class, and this is where I set the remote hostname and port. Later I call the connect method of the winsock object. The data_arraival event fires before the connect event. The value of the state property of the control is 6.

My code is not using any loops to wait for a response back from the remote server. Does anybody know what the cause of his could be???

Your help would be most welcome!!!

Thanks
Mike

Winsock - Control Problem: Missing DATAARRIVAL - Events
Hi there !


Perhaps some you you have experienced a similar problem:


I wrote a little VB-program allowing me to map multiple TCP-Connections

on a single port to another server on a specific port.


The program works just fine, the problem is that when

transferring *many* data, especially when mapping several

connections (which means 2 Winsock Controls per connection, one for

the outgoing and one for the incoming) Visual Basic seems

to "miss" some DATAARRIVAL - events. Data on the outgoing or

on the incoming connection seems to get lost.


When debugging the app with a breakpoint in the DATAARRIVAL - event

everything works perfectly. Slow connections like modem or ISDN-links

also work without any problem.


But LAN - mappings with file-transfers do loose data.


Perhaps YOU can prevent me from going to VC++ and native Winsock-API :-)


many thanks in advance,


Watz

220 Dataarrival
How can I detect the 220 welcome message from an ftp server using the winsock dataarrival event? cheers

DataArrival
What is wrong with this?

Code:
Private Sub wSockRecv_DataArrival(ByVal bytesTotal As Long)
wSockRecv.GetData (Data)
MsgBox Data
End Sub
It just brings up a blank message box.
Thanks in advance

Need Help, Dataarrival
I've been working on a board game program I created, I already finished the single player part, but I want to able to test it over the internet/lan before I actually build it for playing. I am using winsock and I have a client and server, the basics, I can chat back and forth, but I need it to display their name each time they write text to the screen.

Here is where I am stuck:

First Part:-----------------------------------------------------------

Private Sub SendButton_Click()

WinsockClient.SendData YourNameCaption.Caption 'The players name

WinsockClient.SendData ChatRoomSend.Text 'The textbox they write in

ChatRoomReceive.Text = ChatRoomReceive.Text & YourNameCaption.Caption & ": " & ChatRoomSend.Text & vbNewLine 'ChatRoomReceive.Text = The Display chatroombox

ChatRoomReceive.SelStart = Len(ChatRoomReceive.Text)

ChatRoomSend.Text = ""

End Sub

Second Part -----------------------------------------------------------

Private Sub WinsockHost_DataArrival(ByVal bytesTotal As Long)

WinsockHost.GetData incommingdata

ChatRoomReceive.Text = ChatRoomReceive.Text & incommingdata & ": " & incommingdata((2)) & vbNewLine

ChatRoomReceive.SelStart = Len(ChatRoomReceive.Text)

End Sub

---------------------------------------------------------------------
The ((2)) is I want that to be the second data, however it just sends which ever data is last if I use incommingdata... it will only send chatroomreceive.text. I need the player's name first data, then add the chatroomreceive.text data after and display to chatroombox. What kind of code can I write to label the first data and then the second so they come out into the variable places they need to be.

I'm not stupid, but I am having a hard time understanding a lot of the code posted on this forum. I been having problems with this for several hours and haven't found the answer, or have and didn't understand. So please make it as simple as possible and offer explaination for each line of code.

Thanks, Much Appreciated for help

Zack

On .dataarrival Get Ip
Im using winsock to senddata to another application (not mine, but im receiving its packets as if it were, so im not using winsock.connect etc.)

Im wondering, is there a way to find the ip thats sending back to me? If so i could do my loop 1000x faster. Thanks

DataArrival?
ok im using winsocks to connect to a website to get a list of data and store it into a textbox, but the problem is, it doesnt get ALL the data. it gets more than half i guess, but it's missing a huge amount of data. here's my code in the dataarrival event in my winsock:


Code:
Dim strData As String
Winsock1.GetData strData 'gets incoming data
txtdata = txtdata & strData


is there something wrong with that? or maybe the textbox is not big enough to store the data?

DataArrival() Trailer
Hello,

My problem is, I'm on 56K, I send packets of 4K, but one call of SendData at server side generates two DataArrival() events at client side. That should be some sort of packet fragmentation because of the MTU. So, I'm using PeedData() to wait until the last fragment arrives, but this last one is 8 Bytes bigger everytime, whichever be the original packet size. Does it exist a logic explanation??

10x

Spliting DataArrival
ok this is for my program that conects to a chat server not this server sends some data at the front of evry string so it looks like this and every time it sends its diffrent

*&^&%chr(0)chr(1)!:xnickname=john chr(10) admin=0 chr(10) and so on

but every time it sends its diffrent i think its the length of the string cus if i send something diffrent it gets it but cuts the end off if i add more to the string

it is hard to slpit it when to parts of the data arrive at once cus i cant split it

End Of DataArrival Event
Is there any nice way to wait for the hole string in DataArrival?

I mean, if I send a string which will raise the DataArrival event twice. Is there any way to see if it's the end of the string?

DataArrival Behaves ABNORMAL
Hi..
im trying to connect to yahoo site using winsock and this formating
WS1.SendData "GET /config/login?.done=http://chat.yahoo.com&login=joso_&passwd=*mypassword was hidden due to security" & vbCrLf
WS1.SendData "Accept: */*" & vbCrLf
WS1.SendData "Accept-Language: en-us" & vbCrLf
WS1.SendData "User-Agent: Mozilla/4.0 (compatible; CheetaDownload 1.0)" & vbCrLf
WS1.SendData "Host: login.yahoo.com" & vbCrLf
WS1.SendData "Connection: close" & vbCrLf & vbCrLf

when i pass the right Uname and PASSWORD i dnt get any data back from yahoo, and the Data arrival never fires

thought when i pass wrong username and password i get data back

Any help PLEASE

DataArrival Parsing Problem
Hi,

I'm trying to through parse the full webpage source code after I use the winsock GET method to load the webpage.

The problem is, Winsock loads the data in chunks, and a lot of times the string that I'm parsing for doesn't exist.

Is there any way to get wait until Winsock has downloaded the full page?

DataArrival Event Not Happening?
greetings,

i got a small program problem. but first about the vb program. it will send a data to module 1 and wait for module 1 to reply using DataArrival event. upon data arrival event it wil proceed to another subroutine and then repeat the whole process.. the problem is sometimes the program just stops... i think the was a data lost so the DataArrival event did not happen.

any suggestions how can i automatically restart the whole routine when loss of data happens? tnx ya'll

DataArrival Combines More Than One Receipt
My application is based on client and server communication through a socket. I designed a communication protocol sometime back in March and have been following that for packeting and composing the dialogue strings in between the client and the server. Normally when I send data, I first encrypt it and then send it.

Client sends data


Code:
Public Sub SendMessageToServer(ByVal StrMessageToSend As String)

Internet.Connect
If Wsock.State <> sckConnected Then
If Wsock.State <> sckClosed Then Wsock.Close
Wsock.Protocol = sckTCPProtocol
Wsock.RemotePort = SERVER_PORT
Wsock.RemoteHost = StrServerIPAddress
Wsock.Connect
End If

BoolWinsockStillConnecting = True

Do
DoEvents
If BoolForceQuit Then Unload Me
Loop Until Wsock.State = sckConnected
BoolWinsockStillConnecting = False

StrMessageToSend = Encrypt(StrMessageToSend)
Wsock.SendData StrMessageToSend

End Sub



When the guy at the other end (be it the client or the server) receives it, he decrypts it before parsing

it.

Server receives data

Code:
Private Sub WSock_DataArrival(Index As Integer, ByVal bytesTotal As Long)

On Error GoTo ErrorDataArrival

Dim StrMessageRecieved As String
Dim StrMessageToSend As String

WSock(Index).GetData StrMessageRecieved, vbString
StrMessageRecieved = Decrypt(StrMessageRecieved)
If Trim(StrMessageRecieved) <> vbNullString Then Set Message =

ParseMessage(StrMessageRecieved)
SocketPool(Index).UserName = Message.UserName

MDI.sbrPrintMate.Panels("sbrpnlTransactionProgress").Text =

GetMessageTypeString(Message.MessageType) & _
" recieved from " & Message.UserName

If Message.MessageType = DataBaseQuery Then
Call SaveToRepository(Message.MessageData.DataBaseQuery.DataBaseQueryString, InBound)
ElseIf Message.MessageType = LoginAuthRequest Or Message.MessageType =

MgrSubordinatesRequest Then
'For the time being
'Call SynchronizeData
ElseIf Message.MessageType = UserProfileResponseReadReceipt _
Or Message.MessageType = UserActiveStatusResponseReadReceipt _
Or Message.MessageType = UserRightsResponseReadReceipt _
Or Message.MessageType = DataBaseQueryReadReceipt Then
Call ClearMessageFromRepository(OutBound, Message.MessageID, Message.UserName)
End If

Set Reply = CreateReply(Message)
StrMessageToSend = ComposeMessageString(Reply)

MDI.sbrPrintMate.Panels("sbrpnlTransactionProgress").Text = "Sending " &

GetMessageTypeString(Reply.MessageType) & _
" to " & Reply.UserName

If StrMessageToSend <> vbNullString Then
StrMessageToSend = Encrypt(StrMessageToSend)
WSock(Index).SendData StrMessageToSend
End If

ErrorDataArrival:
If Err <> 0 Then
If Err = RECEIVED_DATA_AFTER_CLIENT_WENT_OFFLINE Then
MDI.sbrPrintMate.Panels("sbrpnlTransactionProgress").Text = "Communication Error: " & _
"The user " & SocketPool(Index).UserName & " has just gone offline. " & _
"Cannot parse data received from the user. Data abandoned."
End If
End If

End Sub



Packeting Mechanism
This is the general design of any one of my packets depending upon the type of message being sent:


Code:

Login Authentication Request: 1

<UserName~Sathyaish|MessageID~00000001|MessageDate~4/4/2003|MessageTime~05:57|MessageT

ype~1|MessageStatus~1|MessageData~{BOD}UserName~Sathyaish|Password~SomeJazzWord{EOD

}|{EOM}>


Login Authentication Response: 2

<UserName~Sathyaish|MessageID~00000002|MessageDate~4/4/2003|MessageTime~05:58|MessageT

ype~2|MessageStatus~1|MessageData~{BOD}IsValidUser~-1{EOD}|{EOM}>


For this, I have the following data structures declared in my protocol module:

Code:

Public Const USER_RIGHTS_COMMAND_COMMAND_DELIMITER = ";"
Public Const OPENING_TAG = "<"
Public Const CLOSING_TAG = ">"
Public Const FIELD_DELIMITER = "|"
Public Const END_OF_MESSAGE = "{EOM}" 'For End Of Message
Public Const KEY_VALUE_PAIR_SEPERATOR = "~"
Public Const BEGINING_OF_DATA = "{BOD}"
Public Const END_OF_DATA = "{EOD}"
Public Const USER_PROPERTY_DELIMITER = "+"
Public Const USER_DELIMITER = ";"
Public Const COMPANY_PROPERTY_DELIMITER = USER_PROPERTY_DELIMITER
Public Const COMPANY_DELIMITER = USER_DELIMITER

Public Enum MessageTypes
LoginAuthRequest = 1
LoginAuthResponse = 2

UserProfileRequest = 3
UserProfileResponse = 4
UserProfileResponseReadReceipt = 5
UserProfileResponseImplementationStatus = 6

UserActiveStatusRequest = 7
UserActiveStatusResponse = 8
UserActiveStatusResponseReadReceipt = 9
UserActiveStatusResponseImplementationStatus = 10

UserRightsRequest = 11
UserRightsResponse = 12
UserRightsResponseReadReceipt = 13
UserRightsResponseImplementationStatus = 14

DataBaseQuery = 15
DataBaseQueryReadReceipt = 16
DataBaseQueryImplementationStatus = 17

JobTransferAuthRequest = 18
JobTransferAuthResponse = 19
JobTransferRequest = 20
JobTransferRequestReadReceipt = 21
JobTransferRequestImplementationStatus = 22

MgrSubordinatesRequest = 23
MgrSubordinatesList = 24

UserCompanyListRequest = 25
UserCompanyList = 26

End Enum

Public Enum MessageStatus
Unread = 1
Read = 2
Implemented = 3
NotImplemented = 4
End Enum


Public Enum ReasonsNotImplemented
InternetConnectionBroken = 1
NetworkLinkBroken = InternetConnectionBroken
SocketConnectionClosedWhileTransmission = 2
RequestTimedOut = 3
QueryFailed = 4
Unknown = 5
End Enum


Public Enum MessageFields
'I break my new year resolution here because these fields are gonna map to a dynamic array returned

by the split function
UserName = 0
MessageID = 1
MessageDate = 2
MessageTime = 3
MessageType = 4
MessageStatus = 5
MessageData = 6
End Enum

Public MessageField As MessageFields


Public Enum KeyValuePairSequence
'I break my new year resolution here because these fields are gonna map to a dynamic array returned

by the split function
Key = 0
Value = 1
Pair = 2
End Enum


Public Enum UserProfileFieldSequence
FirstName = 0
MiddleName = 1
LastName = 2
IsActive = 3
Password = 4
CreationDate = 5
CreationTime = 6
LastUpdatedDate = 7
LastUpdatedTime = 8
GroupID = 9
GroupName = 10
LevelID = 11
LevelName = 12
UserRights = 13
End Enum

Public Enum LoginAuthRequestFieldSequence
UserName = 0
Password = 1
End Enum

Public Enum LoginAuthResponseFieldSequence
IsValidUser = 0
End Enum

Public Enum UserProfileRequestFieldSequence
UserName = 0
Password = 1
End Enum

Public Enum ReasonNotImplementedFieldSequence
ReasonNotImplemented = 0
End Enum

Public Enum UserActiveStatusRequestFieldSequence
UserName = 0
Password = 1
End Enum

Public Enum UserActiveStatusResponseFieldSequence
IsActive = 0
End Enum

Public Enum UserRightsResponseFieldSequence
UserRights = 0
End Enum

Public Enum DataBaseQueryFieldSequence
DataBaseQueryString = 0
End Enum

Public Const STRING_MESSAGE_DATA As String = "MessageData"

Public Const RECEIVED_DATA_AFTER_CLIENT_WENT_OFFLINE =

MSWinsockLib.ErrorConstants.sckBadState
Public Const RECEIVED_DATA_AFTER_SERVER_WENT_OFFLINE =

MSWinsockLib.ErrorConstants.sckBadState




THE PROBLEM
Normally, it all falls in place and works fine. But just now, I noticed that although the client sent two seperate messages, the server received both of them in just one DataArrival event. Because the messages are decrypted, for instance, the first message (let's say for the sake of simplicity) was (53$87) and the second was (79$52), these were decipherable seperately but when concatenated as once single receipt, they form the string 53$8779$52. Note that the numbers 87 and 79 join to form 8779 which is not decipherable by my decryption mecahnism. As a result it throws an error.

Now, I am looking for a short cut to this behaviour of the Winsock control of combining more than one message in the receipts queue at DataArrival. One solution I know, the harder one, would be to change my packeting mechanism. This is painful. Hence I need your help.

PS: Thanks for taking time to read this prolix.

Missing DataArrival * Resolved
When I run the program without break there's a missing data arrival (I kept track by adding the Index to a string every time DataArrival fires, I compared it to a similar string for sends). But when I stepped through it with breakpoints to find the error, everythings accounted for.

Also, after running without breakpoints, I then pause execution and resume. The missing DataArrival gets fired. Weird.

Anybody have an idea?

IRC Parsing DataArrival Into A Listbox.
How would I go about and put the names I recieve when I join a channel into a listbox? the only thing I can do is Pong! a ping? and do commands. I included my client below. it connects to gamesnet but you can change it with a little code.

Problem In DataArrival Event
I am connecting to the remote IP using Winsock control & TCP protocol. I want to take the online information to text file & database. Though my exe is running & connection is established sometimes DataArrival event did not get invoked. Why it is happening?

Winsock Array
i have a basic server client chat program, and want to expand it to many clients and a server, i kno i need a winsock array. i already searched for posts on how to work one, and looked at the tutorial and sample project at winsockvb.com, both of those confused the crap outta me and i have no idea how im supposed to even start doing this, can sum1 gimme a jump start

Winsock Array
Edit by Moderator: Moved from VB Communications Forum

I have a TCP based client/serve application

First I open the server form
then the client.

I have an ontimer event to send data to the server for processing.

This works fine with no problems.

However...

If I close the client form (leaving the server open)
and then reopen the client form, I get the error:
"Wrong protocol or connection state for the requested transaction or request"

Below is most of the relevant code:


Code:
Private Sub Form_Load()
'creates connection to national server via tcpip

'MsgBox tcpClient.State

tcpClient.RemoteHost = "shaysrv.grarshay"
tcpClient.RemotePort = 1001
tcpClient.Connect
end sub

Private Sub Form_Timer()

On Error GoTo form_timer_error



tcpClient.SendData StringtoNatDB

end sub

Private Sub Form_Open(Cancel As Integer)
' Set the LocalPort property to an integer.
' Then invoke the Listen method.
tcpServer.LocalPort = 1001
tcpServer.Listen
End Sub

Private Sub tcpServer_ConnectionRequest _
(ByVal requestID As Long)
' Check if the control's State is closed. If not,
' close the connection before accepting the new
' connection.
If tcpServer.State <> sckClosed Then _
tcpServer.Close
' Accept the request with the requestID
' parameter.
tcpServer.Accept requestID
End Sub
Thanks for your help

Winsock Array
OKay. I say someone post on this somewhere a week ago and after hours of searching I can't find it.

I have a form that acts as server and as client. On it there are 4 winsock controls. I need to be able to connect 3 clients to the server. The server winsock control is the array (wsS) 1-3. The client is wsC.

How do I make it so that when a client wants to connect to the server it knows what port to use (first available).

Here are the thoughts I have had (probably wrong).

Do a loop to check port state and use the first closed port. The problem is I don't know what to do once I find the available port.

Also, I don't know what to set for local and remoteport. Should I do something like 3030 for wsS(0), 3031 for wsS(1), and 3032 for wsS(2) ?

Not to mention what should the port on the wsC be. I thought about 3030 + wsS(Index) .. but how will I know that before I make the connection request.

Anyone have a one form server/client example that uses a winsock array?

Any help would be great.

Winsock Array Not Quite Right
Hello,

Here's the general problem:

I need to be able to load and unload winsocks at run-time. I have a winsock array, and I seem to be able to do this fine. The problem comes when I try to connect with one of these winsocks. The connection attempt goes through, and it is seen on the server side fine, but the winsock itself never sees this conenction. In other words, the Connect event doesn't fire (and the state of the winsock stays at 6, Connecting).

After some more testing, I found that if I load the winsock(s) during the main Form_Load event, everything works ok. It just seems to not fire its connect event when it has been loaded afterwards.

I'm loading the winsock with Load WinsockName(number), and unloading with Unload WinsockName(number).

The Connect event looks like this:

Private Sub WinsockName_Connect(Index As Integer)
'code
End Sub

I'm sure the handler is correct, because when I can get it to work (when the winsock is loaded during Form_Load, Index is the correct, and exactly what I expect it to be).


Thank you for reading - Hopefully someone will be able to help!

-Matthew

Winsock Array
Hey, I'm trying to make a chat, where lets say user1 is the host and user2,3, and 4 connect to him/her. I know I have to create a winsock array. I've searched for it, and found examples....but I am completely lost with understanding it and making it so i can apply it to my chat. Any help would be greatly appreciated.

Thank you!

Jizz

Winsock Array
I have been playing with winsocks for awhile and i think i understand them pretty good and i also understand how arrays work. I never had to use winsock array, but i would like to try. I have a list of 87 websites that is added to list1 and i have winsock1. I would like to open 20 connections at once and then wait one minute, and then disconnect those 20 connects and reconnect to the next 20 till it's done....how would i do this? Here's what im thinking:

VB Code:
dim count as integerfor i = 0 to list1.listcount -1 count = i if count > 19 then 'if more than 19 connections, it will resetcount = count - 19  'will this work?end if load winsock1(count)                 winsock1(count).close                winsock1(count).connection "www.google.com",80   next i   Private Sub Winsock1_Connect(Index As Integer)Winsock1(i).SendData "GET / HTTP/1.1" & vbCrLf  'i'm also stuck at this partWinsock1(i).SendData "Accept: */*" & vbCrLfWinsock1(i).SendData "Accept-Language: en-us" & vbCrLfWinsock1(i).SendData "Accept-Encoding: gzip , deflate" & vbCrLfWinsock1(i).SendData "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" & vbCrLfWinsock1(i).SendData "Host: www.google.com" & vbCrLfWinsock1(i).SendData "Connection: Keep -Alive" & vbCrLf & vbCrLfEnd Sub

Winsock Array?
Is there any way to setup an array of winsocks? I'm trying to setup a chatserver, where any amount of people can join at once. I'm aware of being able to select array when you copy+paste a component, but I'm not sure of what the code would look like to differentiate between each user, and what info to send where etc..

Anyone know?

Edit::
Also, is there a way to have different colours contained within one string?
IE, for connecting to MUD's, which have diffenent colours within the same line, is there anyway to display them with different colours, without writing a new textbox function or something of the sort?

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