UDP Port .NET Server VB6 Client


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





LVL 1
shahzad73Asked:
Who is Participating?
 
pratap_rCommented:
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
 
pratap_rCommented:
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
 
pratap_rCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
shahzad73Author Commented:
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
 
pratap_rCommented:
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
 
shahzad73Author Commented:
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
 
pratap_rCommented:
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
 
shahzad73Author Commented:
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
 
pratap_rCommented:
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
 
shahzad73Author Commented:

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
 
pratap_rCommented:
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
 
shahzad73Author Commented:

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
 
pratap_rCommented:
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
 
shahzad73Author Commented:

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.