|
-
Feb 16th, 2005, 04:15 AM
#1
Thread Starter
New Member
Need help with Winsock. thanks
Guys, i'm working on converting a VB 6.0 program to VB.net.
It was a client progam connected to the server by using TCP/IP. In VB 6.0, it was able to send double type straight away to the server using COM component. The problem is when using VB.net socket class, it only allows me to send byte array instead of double type. Is there any way i can send a double variable ? because i don't want to change the server program.
Thanks
-
Feb 16th, 2005, 11:22 AM
#2
Re: Need help with Winsock. thanks
 Originally Posted by richARD.net
...using COM component.
Which COM component was that ?
Cheers,
NTG
-
Feb 16th, 2005, 02:41 PM
#3
Thread Starter
New Member
Re: Need help with Winsock. thanks
it is the winsock in VB 6.0
-
Feb 16th, 2005, 06:23 PM
#4
Re: Need help with Winsock. thanks
When you did a Winsock.SendData DoubleVar, VB6 took that double and converted it to a byte array. I'm really not sure how (or if) you could achieve the same result in .Net without too much trouble. The .Net way would be to serialize an object to send (whether that is a double or any other object) into a memory stream, send the stream and do the reverse process on the other end.
However, if you can't change the server that could be a problem. This may be an overkill and I hope someone can post a better suggestion, buf if you serialize a double and you copy the memory stream's contents into a byte array, the eight bytes before the last byte of the array are the exact bytes that would be send by the equivalent VB6 process. This is a messy process to say the least...if you can't find another way, you can always use COM Interop and instantiate winsock in your .Net program.
VB Code:
'Code to serialize a double
Dim o As System.IO.MemoryStream = New MemoryStream
Dim oo As Double = 123.45
Dim bBuf(128) As Byte
Dim Buffer As New MemoryStream
Dim Formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Formatter.Serialize(Buffer, oo)
Buffer.Position = 0
Buffer.WriteTo(o)
Buffer.Close()
bBuf = o.ToArray
Cheers,
NTG
-
Feb 16th, 2005, 10:28 PM
#5
Thread Starter
New Member
Re: Need help with Winsock. thanks
Thanks a lot for ur suggestions.
Actually i was already using a winsock COM component without any problem in sending data over to the server. but i realized later that the receiving data part can't use "DataArrival" method anymore so i decided to switch to socket class.
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
|