|
-
Dec 19th, 2007, 11:45 PM
#1
Thread Starter
New Member
winsock problem
I have some problem with winsock sending.
I have 1 Server and too many clients. I made ocx for clients
First Server running open port and listen, then clients connect and request images. Next Server send all images to clients. It works, in frirst time.
Then, Server update some (new) images, and need to send all (new and old) to clients, it cannot send. I did not know why? so I put break point in the function for sending, it show me all images for sending and send all complete but when I took break point off and let the problem run automatic, it did not work. I tried again with msgbox for break in the this functions, it alrert message and I click enter one by one, it works and send all image complete but when I took it off and let it run again automatic, it did not work.
In sending function, because of I send images so I use timer for help because image it is very big file ( 30-150 kb) and it need loop for sending image by image and then after finish ,loop for sending another one.
I am not sure, the problem is timer quickly or not but why first time for connect request, it works ? I tried to close connection from clients (but in server still listen , not stop) and open new connection from clients again. It works and send all images successfull.
Does anyone help me for solve this problem ?
-
Dec 20th, 2007, 02:20 AM
#2
Re: winsock problem
It's very difficult to help without seeing some code. Perhaps you'd post it.
-
Dec 20th, 2007, 04:01 AM
#3
Thread Starter
New Member
Re: winsock problem
This is some of source code :
Public Sub Image_Sending(Index As Integer)
On Error GoTo Error_Image_Sending
Dim Buffer() As Byte, P As Long
iFileNum = FreeFile
iNoDN(Index) = iNoDN(Index) + 1
imgCount = imgCount + 1
If imgCount > UBound(Image_DN) - 1 Then
tmrSendFile(Index).Enabled = False
tmrSendFile(Index).Interval = 0
ImageDN(Index).SendData "Done"
GoTo Exit_Image_Sending
End If
Open sFileName For Binary Access Read Lock Write As iFileNum
ReDim Buffer(lngMIN(LOF(iFileNum), PacketSize) - 1)
Get iFileNum, , Buffer ' read data
P = InStrRev(sFileName, "\")
ImageDN(Index).SendData "FileName=" + Mid(sFileName, P + 1) + "ImageType=" + Str(Image_DN(imgCount).ImageType) & ":" ' send the file name
ImageDN(Index).SendData Buffer ' send first packet
Sleep (1)
Exit_Image_Sending:
Exit Sub
Error_Image_Sending:
GoTo Exit_Image_Sending
End Sub
Public Function lngMIN(ByVal L1 As Long, ByVal L2 As Long) As Long
If L1 < L2 Then
lngMIN = L1
Else
lngMIN = L2
End If
End Function
Private Sub tmrSendFile_Timer(Index As Integer)
On Error GoTo Exc_SendFile
Dim Buffer() As Byte, BuffSize As Long
tmrSendFile(Index).Enabled = False
If iFileNum <= 0 Or ImageDN(Index).State <> sckConnected Then Exit Sub
If Loc(iFileNum) >= LOF(iFileNum) Then ' FILE COMPLETE
Close iFileNum ' close file
iFileNum = 0 ' set file number to 0, timer will exit if another timer event
Call Image_Sending(Index)
Exit Sub
End If
'if the remaining size in the file is smaller then PacketSize, the read only whatever is left
BuffSize = lngMIN(LOF(iFileNum) - Loc(iFileNum), PacketSize)
ReDim Buffer(BuffSize - 1) ' resize buffer
Get iFileNum, , Buffer ' read data
ImageDN(Index).SendData Buffer ' send data
Exit Sub
Exc_SendFile:
Exit Sub
End Sub
Private Sub ImageDN_SendComplete(Index As Integer)
tmrSendFile(Index).Enabled = False
tmrSendFile(Index).Interval = 1
tmrSendFile(Index).Enabled = True
End Sub
-
Dec 20th, 2007, 04:20 AM
#4
Re: winsock problem
Rather than 'blasting' the files using a Timer to control it I'd suggest you use the SendComplete event. ie wait for the SendComplete event to trigger before sending another file.
-
Dec 20th, 2007, 04:39 AM
#5
Thread Starter
New Member
Re: winsock problem
Thank you for your answer , you know you save my life, I tried to thinking about this 2 or 3 days
I tried to add
tmrSendFile(Index).Enabled = False
tmrSendFile(Index).Interval = 1
tmrSendFile(Index).Enabled = True
in function Image_Sending, it works normally.
But it is some of source code in sendcomplete. How to make event complete.
Could you please teach me ? I am not good in VB6 .. sorry...
Please give me some example source code if you can.
-
Dec 20th, 2007, 09:02 AM
#6
Re: winsock problem
 Originally Posted by Doogle
Rather than 'blasting' the files using a Timer to control it I'd suggest you use the SendComplete event. ie wait for the SendComplete event to trigger before sending another file.
Actually that is what it's happening, The SendComplete enables the timer, then in the timer it gets dissabled, so it does not send another packet until another SendComplete event... (He modified my code from some project I posted in the forums)
I think the problem is something else, I think the client application does not read the data from the second file, assuming he's using my code, because I don't think I made the client receive more than one file.
He's probably using the code from here: http://www.vbforums.com/showthread.php?t=377648
Anyways, I don't have time right now to look into it (i'm at work, and I have a lot of stuff to do), but as I was saying before, I think the server actually sends the data, but the client does not read & save the data after the first file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|