Solved

UDP Port   .NET Server     VB6 Client

Posted on 2004-10-08
14
586 Views
Last Modified: 2007-12-19

I want to broadcast information through .NET Server.

I want to open a UDP port in .NET Server and push data to that port.


then i want a VB6 client(s) on multiple systems to read that broad cast.

Please help me with both .NET and VB6 Codes... (how to open UDP port in .NET) and read broadcast from VB6 client

thanks
Shahzad





0
Comment
Question by:shahzad73
  • 8
  • 6
14 Comments
 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
can you please clarify your requirements

from what i understand your vb clients are using udp to bind to some port!? and you want a code in .net which will send info to this port? am i right?

if so this is the code..

for your VB Client (actually your server technically speaking)

Private Sub Form_Load()
      Winsock1.LocalPort = 1234
      Winsock1.Bind
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
      Winsock1.Close
      Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
      On Error Resume Next
      Dim str As String
      Winsock1.GetData str, vbString, bytesTotal
      msgbox str
End Sub

now for your .Net Code... i am putting it in c#.net, vb.net is similar

      using System.Net.Sockets;
      using System.Text;
      
      UdpClient udpc=new UdpClient();
      udpc.Connect("172.25.90.124", 13963);
      Byte[] msg = Encoding.ASCII.GetBytes("Hello..");
      udpc.Send(msg,msg.Length);


hope this helps...

enjoy!
pratap
0
 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
and please change the udpc.Connect() in the .net code to your ip address and port... and make sure you are using udp for protocol in the vb application.
0
 
LVL 1

Author Comment

by:shahzad73
Comment Utility
i want to broadcast information .... that is there should be one port and information should be send to that port. server should start first and open the port say 1234 locally.  

then the client(s) will connect to that server port and start reading information from that port. clients can connect or disconnect to the server port.   server will only pust data on the upd port and all clients connected to the server port should read data from that port.



Shahzad Aslam
0
 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
that is exactly what the code is doing. or do you mean the server is in .net?? in my code the .net code is actually the client

the scenario you are talking about is not exacly broadcasting, it is typical client server communication
0
 
LVL 1

Author Comment

by:shahzad73
Comment Utility
NO i want the server should be in .NET and it should open a port and push data on that port. VB6 clients should connect to this port over internet and get the data.

well the .NET server is just pushing data on one port and all clients are getting information form there....  is it not a broadcast ????

Shahzad
0
 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
ok got it now..

heres a detailed write up..
http://www.c-sharpcorner.com/Network/simpleTcpUdpServerClientPL2.asp

let me know if you have any doubts..

Pratap
0
 
LVL 1

Author Comment

by:shahzad73
Comment Utility
Whops both are in .NET....

I need server in .NET while client in VB6...........     does VB6 also has TCPListener as i understand from the client code...



Shahzad
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
no probs.. all you have to do in your vb code is connect the winsock control to the server port

eg,

Winsock2.Connect "ipaddress", 12345

and on the dataarrival event of the winsock2

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim st As String
Call Winsock2.GetData(st, "string", bytesTotal)
MsgBox st, , "client"
End Sub

whenever the server broadcasts the client will popup a dialog..

hope this is clear?

Enjoy
Pratap
0
 
LVL 1

Author Comment

by:shahzad73
Comment Utility

hello


i came across this article on the net..

http://www.knowdotnet.com/articles/udpbroadcastmessage.html


This is UDP Server....


Can you tell me how to create a UDP client in VB6 and get information from here.


Shahzad
0
 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
right.. this is what i had explained in my first reply.. the vb client you are talking about doesnt connect to a server.. rather the server (or the broadcaster) connects to the client and sends the message to it..

assume that your vb client has the following code
Private Sub Form_Load()
     Winsock1.LocalPort = 2000
     Winsock1.Bind
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
     Winsock1.Close
     Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
     On Error Resume Next
     Dim str As String
     Winsock1.GetData str, vbString, bytesTotal
     msgbox str
End Sub

now the .net broadcaster does this or use the code the site you mentioned uses
     using System.Net.Sockets;
     using System.Text;
     
     UdpClient udpc=new UdpClient();
     udpc.Connect("172.25.90.124", 2000);
     Byte[] msg = Encoding.ASCII.GetBytes("Hello..");
     udpc.Send(msg,msg.Length);

...
instead of the connect statement above you will probably loop through a list of ip addresses and send the message..

hope its clear now?

just run the above vb code first.. and use the code that is present in the knowdotnet site .. you must change the ip address accordingly.. you will receive the message in the vb client

Pratap
0
 
LVL 1

Author Comment

by:shahzad73
Comment Utility

i will try this tomorrow .....

before i go just give me one more question....


how the above scenario works on the internet......

actually i want to write a application in VB6 which can be downloaded by any one on the internet. so when he/she installs the application and starts it... it should connect to a network where my .NET server is sending data.  (actually i want to send stocks exchange information in real time.. my .NET server is getting this information from stocks exchnage and want to forward it to my clients....). so .NET server will be running before VB6 clients comes up and get it.


just explain the steps how the VB6 and .NET will communicate over internet.


i have raised points to 150

Shahzad Aslam
0
 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
cool...

this is one of the methods.. other methods exist... but i am deliberately using UDP and the above discussed techniques..

lets assume a vb client is downloaded and run for the first time.. now what we do in the vbclient is connect to the server which is probably listening on an UDP port itself.. and inform that it is connected.. The server now gets this ip address and adds it to its list.. along with the destination port where the vbclient will listen for incomming udp packets.. now whenever the server decides to send data (broadcast) it will send to the list of ip addresses it has ...

there are quite a few flaws with the above approach. but if you are specific about the architecture this would be a way to go..

the best way would be to make the client refresh its data after a specific time interval rather than the server broadcasting it.. again this can be done through UDP but it wouldnt be broadcasting but rather Request based.

Pratap
0
 
LVL 1

Author Comment

by:shahzad73
Comment Utility

well i proposed to my BOSS that UDP is the best option because you just open a port and all clients will connect to this port and server will not manage the list of clients IP's. and all clients gets data from this port.

is there any way that this can be implemented

Shahzad Aslam
0
 
LVL 11

Accepted Solution

by:
pratap_r earned 150 total points
Comment Utility
the server will have to maintain the list otherwise you will not know where to broadcast your information to.. considering how big the internet is.. now if its intranet this might be possible but even there it is an overkill.. sending the package to 255 machines when you know only 1 machine is running your client..
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
A short article about a problem I had getting the GPS LocationListener working.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now