I have to use winsock control in my ASP.net application. And don't have any idea to use it in ASP.net, but I have used it previously in VB.Net project. What I did in ASP.net is-----
I added its reference and also added it in toolbox. But it got added in Windows Forms section of toolbox.
I dragged winsock control from tool box to a webform and named it as win1, then in code behind(i.e. aspx.vb) I tried to use it by typing win1 then one dot( . ) but it has not given any intellisence.
So how could use winsock control in ASP.net.
Can any send me link to a dummy project in which winsock is used(In ASP.net using VB.Net 2003 only) so that I would have some idea of using winsock in ASP.Net 2003.
And also explain me how to add its control in toolbox.
And why I am not getting intellisence?
Please note that I have to use winsock in ASP.net project using VB.Net and not in core VB.Net.
As when I googled this I got all the project in core VB.Net only.
We have one device called call manager. Four Phones are connected to this device, whenever receiver of any othe Phone is picked up it will send some data to the winsock and I will display that which phone's receiver is picked up.
Actually I have did this in VB.net but not able to do same thing ASP.Net as I neither getting any events of that win1 nor any intellisence at code behind.
Is there anyone who has used winsock control in asp.net?
How to use it?
Ok now I am using one component called Ostro Soft's Winsock Control.
I added its reference then defined it in code as -
Dim WithEvents Wsk_1 As New OSWINSCK.Winsock
Also opened that socket as - Wsk_1.RemoteHost = "126.96.36.199" : Wsk_1.RemotePort = "3001" : Wsk_1.Connect()
Private Sub Wsk_1_OnDataArrival(ByVal bytesTotal As Integer) Handles Wsk_1.OnDataArrival
lblError.Text = "Call Received"
I received data i.e. above sub-routine is called, but that text of label didn't changed.
Why that text of label didn't changed?
I thing I have mistaken socket programming. Actually I am mixing up core VB.Net and ASP.Net's concept of socket programming.
In VB.Net we use used create a socket and display data when some data is received on socket as the software is installed on the machine which is directly connected to our call manager device.
But in ASP.Net the web server is directly connected to that device, so server will receive data and that data should be displayed on client's web page.
Am I right? I am still confused about socket programming.
Is there anyone who have used sockets in ASP.Net application?
hi, I have used tcpclient and tcplistener in a ASP.NET application before. What i did was to create a class file (in my case it is in VB). Create your required socket communication in the class file. In the ASP.NET application, call the methods from the class file. It should work.
Could you please tell me what you did in detail? Or could you send me any link to study this?
Hey onepieceking, could you please send me any link related to this?
It is very similar to what you would do for a window application except this time you create the codes into a class file.
I use this link http://www.eggheadcafe.com/articles/20020323.asp for the start.
I am not getting that code. Actually I need not create TCPListner I want client only, also i don't want to send any thing to the server.
I just want to connect a socket to an IP Address(i.e. to our electronic device). Then that device will send some data to this client then I will process that raw data and sort out phone no. and call type through it and that phone no. I want to display on web page.
How could i use that class file in my code behind?
I created one class file as follows -
Public Class TCPCli
Public Function Fun_Connect() As String
Dim tcpClient As New System.Net.Sockets.TcpClient
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes)
Fun_Connect = "Host returned: " + returndata
If Not networkStream.CanRead Then
Fun_Connect = "cannot not write data to this stream"
If Not networkStream.CanWrite Then
Fun_Connect = "cannot read data from this stream"
And in my project's code behind i used above file as follows -
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As New SocketTest.TCPCli
Dim str As String
str = obj.Fun_Connect
If str <> "" Then
But getting error at line - tcpClient.Connect("192.168.1.187", 3017) and error is - No connection could be made because the target machine actively refused it
It means the other side, that you are trying to connect to, is not listening at that port or it is not listening at all.
By the way, the code seems okay. Check the other side.
The web page got hanged for about two minutes after that gives error - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I am receiving data on same IP Address and port No. in my VB.Net application.
Are you testing both asp.net and vb.net application on the same computer? If so, maybe you can try changing the IP address for both applications to "127.0.0.1".
No firstly I tested on separate computers in same network. Then I tested on same computer also.
When I use Ostro Soft's Winsock Control I receive the data but there is no change on web page. Could u please tell me why so?
Let me tell you my problem again, actually I want to implent live monitoring.
On my web page I have taken one datagrid, in this firstly I display list of phone nos and our channel nos and establish connection of one socket with our 'call manager' device. Thats it.
Now suppose after half an hour we got a call (incoming call) then that 'call manager' will send us some raw data to which we will process in our code and find out on which phone no. we have got that call and then we will display 'incoming call' in front of that phone no. in our datagrid.
Using Ostro Soft's winsock control I am receiving data at socket but when I bind that new data to datagrid then there no change in it. So then I simply written the above code to change text of label. But it is also not working.
Do I need to automatically refresh the page to apply these changes?
If so then how could I refresh the page automatically? Should I use timer control? I don't how to use timer control.
Or simply tell me some other methods to implement live monitoring. The code given above that use TcpClient is of no use for me because they gives results when they receive instant reponse from TcpServer but in my case it is not sure that when will that server (or 'call manager device') send data. It may send data after 15 minutes or after 30 min. or 1 hour or will not send data for whole day.
I have seen something like SNMP protocol to do this. What is it? Is it helpful for me? Is there anyone who is using it?
Please tell me one thing - If I create TCPClient in ASP.Net application and TCPServer in core VB.net application then whether they will be able communicate with each other.
Also ASP.net application and VB.Net application will be running on different machines but communicating on same port.
Is it possible?
They should work. That was what I did last time. TcpClient in a VB.NET class for ASP.NET web application and TcpServer for core VB.NET application.
Correct me if I am wrong. When you say ASP.NET and VB.NET in different machines, I am taking it as the web server and VB.NET application are in the same machine and that you are accessing the web server from another machine.