Hai,
I am new to VB.Net programming, directly doing socket programming. In C, I
will be able to map the message arrived in a socket directly to a structure.
Is this possible in VB.Net. Can anyone please help me with some sample
codings and guidance?
Can you also suggest some other news group available for socket programming
in VB.Net?
My TCP/IP server program is done in C. I have to create a TCP/IP client
socket in VB.Net and transfer some data between the server and client. The
data sent should be in predefined structure with a header and body.
Depending on the Message Type in the header, I have to map the arrived
message to the corresponing structure. I have done this in C, but not aware
of implementing in VB.Net. Please guide me.
Thanks in advance,
Uma 10 3989
Yes Uma, actually you can directly serialize objects through the
socket. It's quite easy you can just use a Networkstream and a
Formatter to do that. The process is simply to serialize the object to
an array of bytes, send it, and deserialize it on the other end.
-tom
Uma - Chellasoft ha scritto:
Hai,
I am new to VB.Net programming, directly doing socket programming. In C, I
will be able to map the message arrived in a socket directly to a structure.
Is this possible in VB.Net. Can anyone please help me with some sample
codings and guidance?
Can you also suggest some other news group available for socket programming
in VB.Net?
My TCP/IP server program is done in C. I have to create a TCP/IP client
socket in VB.Net and transfer some data between the server and client. The
data sent should be in predefined structure with a header and body.
Depending on the Message Type in the header, I have to map the arrived
message to the corresponing structure. I have done this in C, but not aware
of implementing in VB.Net. Please guide me.
Thanks in advance,
Uma
Thanks for your guidance for using Networkstream and Formatter. But I am
unable to come out with the exact solution even after having a look at
Networkstream. If time permits, can you please give me a sample code for
mapping the binary message from a socket directly to a structure in VB.Net.
Regards,
Uma
<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Yes Uma, actually you can directly serialize objects through the
socket. It's quite easy you can just use a Networkstream and a
Formatter to do that. The process is simply to serialize the object to
an array of bytes, send it, and deserialize it on the other end.
-tom
Uma - Chellasoft ha scritto:
>Hai,
I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can anyone please help me with some sample codings and guidance?
Can you also suggest some other news group available for socket programming in VB.Net?
My TCP/IP server program is done in C. I have to create a TCP/IP client socket in VB.Net and transfer some data between the server and client. The data sent should be in predefined structure with a header and body. Depending on the Message Type in the header, I have to map the arrived message to the corresponing structure. I have done this in C, but not aware of implementing in VB.Net. Please guide me.
Thanks in advance, Uma
Hello,
UMA, at the moment I am a little overwhelmed (I am replying between
compilations) but I found a few links with code: http://www.ureader.com/message/1084726.aspx http://www.developmentnow.com/g/4_20...ket-stream.htm http://www.thescripts.com/forum/thread381461.html
if you have problems let us know. If none works, I will try to spare
some time later to write your classes. Ciao,
-Tommaso
Uma - Chellasoft ha scritto:
Thanks for your guidance for using Networkstream and Formatter. But I am
unable to come out with the exact solution even after having a look at
Networkstream. If time permits, can you please give me a sample code for
mapping the binary message from a socket directly to a structure in VB.Net.
Regards,
Uma
<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Yes Uma, actually you can directly serialize objects through the
socket. It's quite easy you can just use a Networkstream and a
Formatter to do that. The process is simply to serialize the object to
an array of bytes, send it, and deserialize it on the other end.
-tom
Uma - Chellasoft ha scritto:
Hai,
I am new to VB.Net programming, directly doing socket programming. In C,
I
will be able to map the message arrived in a socket directly to a
structure.
Is this possible in VB.Net. Can anyone please help me with some sample
codings and guidance?
Can you also suggest some other news group available for socket
programming
in VB.Net?
My TCP/IP server program is done in C. I have to create a TCP/IP client
socket in VB.Net and transfer some data between the server and client.
The
data sent should be in predefined structure with a header and body.
Depending on the Message Type in the header, I have to map the arrived
message to the corresponing structure. I have done this in C, but not
aware
of implementing in VB.Net. Please guide me.
Thanks in advance,
Uma
Tom, thanks for the links, but I am sorry to say that all links contains
samples in C#. If possible, pls try to send me some links in VB.Net. But
these links are providing me a a good idea, and I am trying to work it out
in VB.Net. As I have been working in C for a long time, it is taking some
time for me to shift to VB.Net.
Thanks,
Uma
<to**************@uniroma1.itwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hello,
UMA, at the moment I am a little overwhelmed (I am replying between
compilations) but I found a few links with code:
http://www.ureader.com/message/1084726.aspx http://www.developmentnow.com/g/4_20...ket-stream.htm http://www.thescripts.com/forum/thread381461.html
if you have problems let us know. If none works, I will try to spare
some time later to write your classes. Ciao,
-Tommaso
Uma - Chellasoft ha scritto:
>Thanks for your guidance for using Networkstream and Formatter. But I am unable to come out with the exact solution even after having a look at Networkstream. If time permits, can you please give me a sample code for mapping the binary message from a socket directly to a structure in VB.Net.
Regards, Uma
<to**************@uniroma1.itwrote in message news:11*********************@m79g2000cwm.googlegr oups.com...
Yes Uma, actually you can directly serialize objects through the
socket. It's quite easy you can just use a Networkstream and a
Formatter to do that. The process is simply to serialize the object to
an array of bytes, send it, and deserialize it on the other end.
-tom
Uma - Chellasoft ha scritto:
Hai,
I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can anyone please help me with some sample codings and guidance?
Can you also suggest some other news group available for socket programming in VB.Net?
My TCP/IP server program is done in C. I have to create a TCP/IP client socket in VB.Net and transfer some data between the server and client. The data sent should be in predefined structure with a header and body. Depending on the Message Type in the header, I have to map the arrived message to the corresponing structure. I have done this in C, but not aware of implementing in VB.Net. Please guide me.
Thanks in advance, Uma
Ok here we go. Here is an example sending from an application to
another application
the image contained in a picture box
Sorry not much refined but I am in the middle of a huge project. It
works anyway...
I have coded it so that yone can send object of any size (buffer can be
adjusted: could
use a few MB buffer) I used different small numbers just to try...
In case of problems post here. Others may contribute with some
important suggestion...
Sorry I am in a hurry...
-Tommaso
SERVER SIDE CODE
------------------------------------------------------------------------------
Dim SizeOfTheReceiveBuffer As Integer = 2048 'change
appropriately
Const Port As Integer = 60000 'change appropriately
Dim LocalIP As System.Net.IPAddress =
IPAddress.Parse("127.0.0.1")
Dim TcpListener As New TcpListener(LocalIP, Port)
Try
TcpListener.Start()
Catch ex As Exception
MsgBox("Port may be already in use by another app" & _
vbCrLf & ex.Message)
Exit Sub
End Try
Dim Socket As Sockets.Socket
Do
If TcpListener.Pending Then
Socket = TcpListener.AcceptSocket 'wait for client
call
Socket.ReceiveBufferSize = SizeOfTheReceiveBuffer
Dim ReceiveBuffer(SizeOfTheReceiveBuffer - 1) As Byte
'Receive object
Dim MemoryStream As New System.IO.MemoryStream
Dim BytesActuallyReceived As Integer
Do
BytesActuallyReceived =
Socket.Receive(ReceiveBuffer, SizeOfTheReceiveBuffer, SocketFlags.None)
If BytesActuallyReceived 0 Then
MemoryStream.Write(ReceiveBuffer, 0,
BytesActuallyReceived)
Else
Exit Do
End If
Loop
Try
Dim o As Object
With New BinaryFormatter
MemoryStream.Position = 0
o = .Deserialize(MemoryStream)
Me.PictureBoxReceived.Image = DirectCast(o,
Image)
End With
Catch ex As Exception
MsgBox(ex.Message)
Finally
MemoryStream.Close()
End Try
Else
Application.DoEvents()
End If
Loop
Socket.Shutdown(SocketShutdown.Both)
Socket.Close()
TcpListener.Stop()
CLIENT SIDE CODE
--------------------------------------------------------------------------------
Dim SizeOfTheSendBuffer As Integer = 1024 'change appropriately
Const Port As Integer = 60000 'change appropriately
Dim ServerAddress As String = "127.0.0.1" 'change
appropriately if not local
Dim MyObject As Object = Me.PictureBox1.Image
Dim ObjectLength As Long
'Connect to the server
Dim Socket As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
Try
Socket.Connect(ServerAddress, Port)
Catch ex As Exception
MsgBox("(Server may be not responding)" & vbCrLf & _
ex.Message)
Exit Sub
End Try
Socket.SendBufferSize = SizeOfTheSendBuffer
If Not Socket.Connected Then
MsgBox("Unable to connect to host " & ServerAddress)
Else
Using MemoryStream As New MemoryStream
'Serialize object
Dim BinaryFormatter As New BinaryFormatter
With New BinaryFormatter
.Serialize(MemoryStream, MyObject)
ObjectLength = MemoryStream.Position
End With
Dim SendBuffer(SizeOfTheSendBuffer - 1) As Byte
Dim BytesActuallyRead As Integer
'Send pieces of the object
MemoryStream.Position = 0
Do While MemoryStream.Position < ObjectLength
BytesActuallyRead = MemoryStream.Read(SendBuffer,
0, SizeOfTheSendBuffer)
Socket.Send(SendBuffer, BytesActuallyRead,
SocketFlags.None)
Loop
MemoryStream.Close()
Socket.Close()
End Using
End If
Uma - Chellasoft ha scritto:
Tom, thanks for the links, but I am sorry to say that all links contains
samples in C#. If possible, pls try to send me some links in VB.Net. But
these links are providing me a a good idea, and I am trying to work it out
in VB.Net. As I have been working in C for a long time, it is taking some
time for me to shift to VB.Net.
Thanks,
Uma
<to**************@uniroma1.itwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hello,
UMA, at the moment I am a little overwhelmed (I am replying between
compilations) but I found a few links with code: http://www.ureader.com/message/1084726.aspx http://www.developmentnow.com/g/4_20...ket-stream.htm http://www.thescripts.com/forum/thread381461.html
if you have problems let us know. If none works, I will try to spare
some time later to write your classes. Ciao,
-Tommaso
Uma - Chellasoft ha scritto:
Thanks for your guidance for using Networkstream and Formatter. But I am
unable to come out with the exact solution even after having a look at
Networkstream. If time permits, can you please give me a sample code for
mapping the binary message from a socket directly to a structure in
VB.Net.
Regards,
Uma
<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Yes Uma, actually you can directly serialize objects through the
socket. It's quite easy you can just use a Networkstream and a
Formatter to do that. The process is simply to serialize the object to
an array of bytes, send it, and deserialize it on the other end.
-tom
Uma - Chellasoft ha scritto:
Hai,
I am new to VB.Net programming, directly doing socket programming. In
C,
I
will be able to map the message arrived in a socket directly to a
structure.
Is this possible in VB.Net. Can anyone please help me with some sample
codings and guidance?
Can you also suggest some other news group available for socket
programming
in VB.Net?
My TCP/IP server program is done in C. I have to create a TCP/IP
client
socket in VB.Net and transfer some data between the server and client.
The
data sent should be in predefined structure with a header and body.
Depending on the Message Type in the header, I have to map the arrived
message to the corresponing structure. I have done this in C, but not
aware
of implementing in VB.Net. Please guide me.
Thanks in advance,
Uma
Forgot to say that, clearly, in place of the image you can clearly use
any object.
The code is always the same for any object.
Also you can change the type of serialization if appropriate (eg.,
XML).
-tom
DataTime(tm) - Community Client Edition (free) http://cam70.sta.uniroma1.it/Community/
Thanks Tom, your sample codings was very helpful. I am able to serialize the
object and send it through the socket. In middle of your busy work, u have
sent me some sample codings which was very clear for me to understand about
Serialization.
As mentioned earlier, my client socket is in VB.Net and the server socket in
VC++ console application. While serializing and sending an object from
VB.Net, I am actually sending the entire details of the structure, and not
the required data alone. Say I am having a structure with two short data
types, now it is enough for me to transfer 4 bytes of data alone. But by
serialization, I am transferring some 159 bytes of data. Is it possible for
me to send the 4 bytes alone?
I am able to sending individual elements of the structure by using
BitConvertor.GetBytes. But I don't want this as the application contains
several structures with several members in all structures. How can I send
the data aloen?
Sorry for disturbing you, please give me some ideas and links for my case.
Thanks,
Uma
<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Forgot to say that, clearly, in place of the image you can clearly use
any object.
The code is always the same for any object.
Also you can change the type of serialization if appropriate (eg.,
XML).
-tom
DataTime(tm) - Community Client Edition (free) http://cam70.sta.uniroma1.it/Community/
hi Uma
What you are asking I think is exactly the same question in the first
link I provided, if I remember well.
Of course is possible. If you do not have control on the receive
process and you just need to send only a few bytes you just put them in
the Stream and send them away. That's it. The process is the same. You
simply skip the serialization part.
-t
Uma - Chellasoft ha scritto:
Thanks Tom, your sample codings was very helpful. I am able to serialize the
object and send it through the socket. In middle of your busy work, u have
sent me some sample codings which was very clear for me to understand about
Serialization.
As mentioned earlier, my client socket is in VB.Net and the server socket in
VC++ console application. While serializing and sending an object from
VB.Net, I am actually sending the entire details of the structure, and not
the required data alone. Say I am having a structure with two short data
types, now it is enough for me to transfer 4 bytes of data alone. But by
serialization, I am transferring some 159 bytes of data. Is it possible for
me to send the 4 bytes alone?
I am able to sending individual elements of the structure by using
BitConvertor.GetBytes. But I don't want this as the application contains
several structures with several members in all structures. How can I send
the data aloen?
Sorry for disturbing you, please give me some ideas and links for my case.
Thanks,
Uma
<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Forgot to say that, clearly, in place of the image you can clearly use
any object.
The code is always the same for any object.
Also you can change the type of serialization if appropriate (eg.,
XML).
-tom
DataTime(tm) - Community Client Edition (free) http://cam70.sta.uniroma1.it/Community/
Thanks Tom, finally I am able to transfer binary data from VB.Net to C and C
to VB.Net and map it to the required structure.
The first link had my exact requirement. Actually I saw it earlier, and
didn't concentrate on it as it was in C#, and I thought that memory
managements were not possible in VB.Net, but now I have done the same way in
VB.Net and it is working fine.
Regards,
Uma
<to**************@uniroma1.itwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
hi Uma
What you are asking I think is exactly the same question in the first
link I provided, if I remember well.
Of course is possible. If you do not have control on the receive
process and you just need to send only a few bytes you just put them in
the Stream and send them away. That's it. The process is the same. You
simply skip the serialization part.
-t
Uma - Chellasoft ha scritto:
>Thanks Tom, your sample codings was very helpful. I am able to serialize the object and send it through the socket. In middle of your busy work, u have sent me some sample codings which was very clear for me to understand about Serialization.
As mentioned earlier, my client socket is in VB.Net and the server socket in VC++ console application. While serializing and sending an object from VB.Net, I am actually sending the entire details of the structure, and not the required data alone. Say I am having a structure with two short data types, now it is enough for me to transfer 4 bytes of data alone. But by serialization, I am transferring some 159 bytes of data. Is it possible for me to send the 4 bytes alone?
I am able to sending individual elements of the structure by using BitConvertor.GetBytes. But I don't want this as the application contains several structures with several members in all structures. How can I send the data aloen?
Sorry for disturbing you, please give me some ideas and links for my case.
Thanks, Uma
<to**************@uniroma1.itwrote in message news:11*********************@m79g2000cwm.googlegr oups.com...
Forgot to say that, clearly, in place of the image you can clearly use
any object.
The code is always the same for any object.
Also you can change the type of serialization if appropriate (eg.,
XML).
-tom
DataTime(tm) - Community Client Edition (free) http://cam70.sta.uniroma1.it/Community/
Good. In general in the .net you can always look at c#. The classes are
just
the same: you only need to change the order of some keywords, that's it
.... :)
-t
Uma - Chellasoft ha scritto:
Thanks Tom, finally I am able to transfer binary data from VB.Net to C and C
to VB.Net and map it to the required structure.
The first link had my exact requirement. Actually I saw it earlier, and
didn't concentrate on it as it was in C#, and I thought that memory
managements were not possible in VB.Net, but now I have done the same way in
VB.Net and it is working fine.
Regards,
Uma
<to**************@uniroma1.itwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
hi Uma
What you are asking I think is exactly the same question in the first
link I provided, if I remember well.
Of course is possible. If you do not have control on the receive
process and you just need to send only a few bytes you just put them in
the Stream and send them away. That's it. The process is the same. You
simply skip the serialization part.
-t
Uma - Chellasoft ha scritto:
Thanks Tom, your sample codings was very helpful. I am able to serialize
the
object and send it through the socket. In middle of your busy work, u
have
sent me some sample codings which was very clear for me to understand
about
Serialization.
As mentioned earlier, my client socket is in VB.Net and the server socket
in
VC++ console application. While serializing and sending an object from
VB.Net, I am actually sending the entire details of the structure, and
not
the required data alone. Say I am having a structure with two short data
types, now it is enough for me to transfer 4 bytes of data alone. But by
serialization, I am transferring some 159 bytes of data. Is it possible
for
me to send the 4 bytes alone?
I am able to sending individual elements of the structure by using
BitConvertor.GetBytes. But I don't want this as the application contains
several structures with several members in all structures. How can I send
the data aloen?
Sorry for disturbing you, please give me some ideas and links for my
case.
Thanks,
Uma
<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Forgot to say that, clearly, in place of the image you can clearly use
any object.
The code is always the same for any object.
Also you can change the type of serialization if appropriate (eg.,
XML).
-tom
DataTime(tm) - Community Client Edition (free) http://cam70.sta.uniroma1.it/Community/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jerome Symons |
last post by:
Hi everyone,
I have developed a C# client/server system that creates bitmap images
at the server and sends them to the client as an array of bytes using
a Socket.
When the data rate through...
|
by: mscirri |
last post by:
The code below is what I am using to asynchronously get data from a
PocketPC device. The data comes in fine in blocks of 1024 bytes but
even when I send no data from the PocketPC constant blocks of...
|
by: Crirus |
last post by:
Hi all!
I use a webClient for requesting data from a server of mine.
Should I worry about long ammount of data sent by server in the client side?
Or, another way, should I send some kind of a...
|
by: Macca |
last post by:
Hi,
I have a synchronous socket server which my app uses to read data from
clients.
To test this I have a simulated client that sends 100 byte packets.
I have set up the socket server so...
|
by: Macca |
last post by:
My app has an asynchronous socket server. It will have 20 clients connected
to the server. Each client sends data every 500 millisecondsThe Connections
once established will not be closed unless...
|
by: Macca |
last post by:
Hi,
I am writing an asychronous socket server to handle 20+ simulataneous
connections.
I have used the example in MSDN as a base. The code is shown at end of
question.
Each connection has a...
|
by: Jens |
last post by:
Hello,
I have been looking for some C-code which listens on a user-defined port
for incoming data traffic. When data is received, the data is written to a
file.
I found some C-code (server)...
|
by: Pat B |
last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol
using C#. I have implemented it using BeginReceive and EndReceive
calls so as not to block when waiting for data from the...
|
by: starter08 |
last post by:
Hi,
I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket.
On the server side I have a cgi...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |