Hi Dw.

I'm having a client server which the server read a text file line by line and send each line to the client upon client connection.

The problem I'm having is that on the client side the data is combined, meaning I get all lines that are on the file at once but what I want is to get each line just like how it is sent. This is the server side code I have.

Dim myFileName As String
Dim myLine As String
Dim FileNum As Long
myFileName = "c:\myfile.txt"
FileNum = FreeFile
Close FileNum
Open myFileName For Input As FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, myLine
Winsock1.SendData myLine
' MsgBox myLine
Loop

For now the file only consist of 2 lines but the client display a message containing all the text file data in one message box but it should be displaying two messages.

Here is my client side DataArrival code:

 Dim strData As String
 Winsock1.GetData strData, vbString
 MsgBox strData

I think I should use a For Each strData but don't know how. Anyone who knows a better solution.

Thanks but that didn't work. Or maybe I'm doing it wrong. I'm using VB5.0

Using such old tools can catch folk unaware of issues in those systems. For example an old VB6 app uncovered WinSock issues that were fixed in version 6 (not kidding) of the patches for VB6.

There's another issue in your design. It looks like you fling the lines over without handshake or a protocol. This is trouble in the making as well.

-> Since Visual Studio has current versions for free in the Express line, you may be seeing a code or bug issue. Only you would know that as very few today would have VB5 to try it out on.

In parting, move forward to a current system, check for patches and implement a protocol.

Lol. Well I do use VB.NET 2010 but for this project I'm developing I find VB5.0 a bit easy its not too complicated with connections or so like the Sockets in VS. In VB5.0 you only drag the Winsock and assign properties then start listening/connection request.

Well I've manage to find something that helps but with this the problem is that its only works perfect when its likes. For now I have updated my text file and now I'm having 5 lines and I want on the client side to also split or separate the message so that I can write this lines exactly as they are on a server.

Sometimes the file created on the client is 810Bytes which when its this size if I open the file I find everything in place as its suppose to, but if I delete the file on the client side and rerun my app its sometimes create a file with 702Bytes, this is mostly created even if I didn't delete the file I will get the whole message in just 1 or 2/3/4 lines only once often I get 5 lines.

I don't know why is this odd activity is happening. I've used the DoEvents after Winsock1.SendData myLine but I have to write 12 times the DoEvents in order to be able to at least get the 810 or 805Bytes which appear to be how I want it but this is done rarely maybe once in 6 or 10 tries.

Some articles stated that the reason why the message is mixed up is that the Winsock is so fast (its sends data so fast that the messages get combined on DataArrival.

Which is why you implement a protocol. This can be as simple as putting in line terminators so you can parse the lines on the receiving app to implementing a complete "Hey send me the next line", "here's the next line" etc.

Yeah, this whole project consist of 5 parts which I don't want them to be done by the same program, so the best approach or method I thought of was to have the VB5.0 to do these apps that will do the data transmission (sharing) this way the I will have another app which is the app I will do in VS2010 to read this text file and split each record accordingly so that it will be inserted in to a database then the very same app will also listen for external client connection on another port.

So this will for now be connected by 2 types of clients namely (Windows Forms based clients, and Android based clients) so that's where the VS2010 will come in handy. The main reason why I didn't want to use it throughout the project was that there are some parts where I don't want an installable program only stand alone program.

Now coming back to the topic. I've managed to solved this with the help I found on this site: http://www.vbforums.com/showthread.php?624135-Help-with-winsock-data-arrival

Thank you so much.

I see they wrote the code to implement my suggestion of "This can be as simple as putting in line terminators so you can parse the lines on the receiving app"

So far I've yet to find Android to use other than an installable program. Where did you find a way to avoid the APK or Android installer?

PS. The solution there has an issue. What if your data strings have a comma in them?

Edited 8 Months Ago by rproffitt

I think you got it the other way around. Well just the clarify this. These VB5.0 programs I did they communicate both they will be on different PCs and the server is on the side where the data gets in(arrive) from another PC on a different network, so on that other PC that's generates these data its only generates the data in a special or should I say in my format and on this server that we are talking about here that's the part that will look for a special file and when found.

This file will be opened (what I'm doing here is do send the data to another computer before the data is sent out to the user) I don't want the user nor the data generator to use the same PC so I had to transfer the file to another computer and that's the computer that will also send the data to clients(users).

Coming to clients all other software can be installable but not on the Generator and center computer, only from this computer where its sends or communicates with users can be installable and on users the software can be installed.

As of comma in a message, that's not possible in this because as I've said the message is formatted bÚy this server that we are talking about here and I used the * to separate the records on each line and used # at the end of each line to indicate that its the end of line.

Well don't stress I've already managed to solve this. This app I'm developing now on VS2010 is responsible of splitting the data and also inserting it to a data base and also add another parts which is determined by the message and this is added on a secure database which when the user connects to this VS2010 server I did then the user will be verified to see his/her points and this data will be sent but not all only certain parts will be sent to the client.

When a client click the data on a listview the points will be checked and if the user has enough points then will proceed else this will be denied.

I know I could have achieved all this within the VS but I didn't want to use it for the first parts only in the third part and to the apps that will be used by a user. As of Android, I have someone who is experienced with it so he's the one who will be developing that app as he is using an Android Studio which I'm not familiar with.

This question has already been answered. Start a new discussion instead.