Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

UDP Port   .NET Server     VB6 Client

Posted on 2004-10-08
14
Medium Priority
?
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 11

Expert Comment

by:pratap_r
ID: 12258888
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
ID: 12258902
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
ID: 12274016
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

by:pratap_r
ID: 12274181
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
ID: 12284150
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
ID: 12284528
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
ID: 12286128
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12286214
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
ID: 12286312

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
ID: 12286461
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
ID: 12286774

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
ID: 12289127
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
ID: 12294709

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 600 total points
ID: 12295730
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Simple Linear Regression
Starting up a Project

597 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