.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

cancelar un socket asincronico

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :.NET Framework

Saludos a todos,

quisiera saber como puede cancelar la lectura de un socket asincronico, ya que una ves que inicio la lectura de forma asincronica, no se como detener el evento

si alguien me podria ayudar se lo agradeceria



View Complete Post

More Related Resource Links

Webservice using socket layer programming



   I want to access a webservice in asp.net programming. This webservice was done using socket layer programming and also i am having the ipaddress and port address. Did any one know about how to access webservice using socket layer and if know let me know how to access the webservice. Thank you

10 MB File Download In ASP.NET Socket Error

Hi,I received the following error message, when downloading file of 10 MB. Please let me know the solution. I already configured the httpRuntime value to <httpRuntime maxRequestLength="10250 " executionTimeout="1000". Still I am getting the error message.The description for Event ID ( 0 ) in Source (XXXXX) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Unable to read data from the transport connection: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full. Source: mscorlib TargetSite: Void HandleReturnMessage(System.Runtime.Remoting.FileUploading.IFileUpload, System.Runtime.Remoting.FileUploading.IFileUpload) StackTrace: Server stack trace:    at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)   at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)   at System.IO.BinaryReader.ReadBytes(Int32 count)   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadArrayAsBytes(ParseRecord pr)   at System.Runtime.Seri

Windows UDP Socket Buffer (Maximum)

I am receiving on a socket (C#) and setting the UDP buffer size to br 10 Mb - and creating 16 such sockets. But I see missed UDP packets (they have  a unique seq number in them). When I read back "ReceiveBufferSize" it return the size I set it to - 10Mb.   My question is - what is the maximum internal socket buffer size allowed by Windows (Win Server 2008) ?   Wierdly when I also start Netmon in the background on the receiving machine - I do not see any missed packets.   Does Netmon modify internal windows socket buffers (increase them) - how can I go about doing this with my app ?   Thanks

WCF Service for socket TCP

Hi all, I have a problem. I have to implement a WCF service that responds to clients that do not use a WCF technology. Clients use sockets and TCP. What might be the best solution?

Can't bind a UDP socket to a port

using System; using System.Net; using System.Net.Sockets; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int port = 11000; Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Any, port); try { socket.Bind(ipendpoint); Console.WriteLine("Successfully bound to port " + port); } catch (SocketException e) { Console.WriteLine("Winsock error: " + e.ErrorCode.ToString() + ", " + e.Message.ToString()); } Console.Read(); } } } I get the error code [b]10022[/b] when trying to bind the UDP socket, which is "Invalid argument specified". This is the same for all the UDP server examples on the internet at the binding stage, as well as the MSDN one. It will work if the port is 0, but not if the port is anything but 0. TCP binding works fine, and I can make a UDP server on any port with Java (the binding works fine) but in C# it gives me this error. The code works for everyone I've asked to try it, and I've got the latest NET framework (version 4) and Windows XP with SP3 so I know the commands are supported by the OS (also, Visual C# 2010 Express and 2008 Express both give this error). Any ideas to fix it?

How to setup windows server 2008 to enable socket communication?

I wrote a simple socket program, which listens to the 82 port, then receives and sends data through it. I tested the program on my local machine and it works fine, but after I published the program onto my windows server 2008, it does not work anymore. I guess it should be the firewall causing the problem, so I added rules to allow 82 port for both in and out bound, and I also add my application to the allowed program list for passing firewall, but still doesn't work, how could I solve it?   The windows server 2008 machine has a public network IP address, while my workstation is in a local network without public IP address, I connect to server 2008 through a router which has a public IP address. Is that the problem?   thanks! Regards! directfriends.net

Asynchronous WebService with Tcp/Ip Socket?

Hi people, Our code is written in VS 2005, 2008, mostly. And we just migrated to 2010. Originally we planned on connecting one webservice to another webservice. But this data transfer have to pass through a stand alone Tcp/Ip socket app whcih acts like a firewall/filter. Request and response all have to go through this Tcp/Ip socket app. From what I've heard our webservice is a synchronous webservice which doesn't goes well with the socket app. Data/connection could be lost waiting for the response. So I am thinking we need a asynchronous webservice. Does WCF have webservice capabilities that use Tcp/Ip socket? I know that WCF is a summation of webservice, Tcp/Ip, Namepipe, etc. But can I use WCF as a webservice and Tcp/Ip at the same time? All using asynchronously? Give example plz? BlueMarker

client socket connecting in loop

I'm running Visual Studio Express 2008 C++ on a Windows XP machine. In trying to use System::Net TCP communication I came upon the following problem ... I'm connecting to a server by trying clientSocket->Connect() in a loop, because I need to wait until the server is up. If the connection fails, I just use an empty catch. I assume this is not really a good way to do it (giving catch functionality). using namespace System::Net; ... bool is_onLine = false; Socket clientSocket; ... while(!is_onLine){ try{ this->clientSocket->Connect(serverIpEndpoint); if (clientClientSocket->Connected){ // Print out connection succeeded is_onLine = true; } else{ is_onLine = false; } } catch (SocketException^ err){ } } I can't seem to do this any other way. Not having a catch makes the program throw an exception whenever I set up my client to use Socket->Connect() when the server is not running. Is there a better way to have the client trying to connect to the server in a loop?

Socket receiving Data Loss

Hi Friends,   I have a Real Time Client/server application which should process received data and send back result with in milliseconds.Application is working fine when it runs in normal load. During my testing phase i tested by sending 100 message to clients in One seconds, But Client Application will only process 40 message , But sever will send all 100 message to clients. I would like to know Is there any DATA LOSS occurring in Client Side. Here is the code i wrote to receive data from sever. Private Sub sockDataArrival(ByVal ar As IAsyncResult) Dim state As StateObject = CType(ar.AsyncState, StateObject) Dim client As Socket = state.workSocket Dim bytesRead As Integer Try bytesRead = client.EndReceive(ar) Catch Exit Sub End Try Try Dim Data() As Byte = state.buffer If bytesRead = 0 Then client.Shutdown(SocketShutdown.Both) client.Close() RaiseEvent onDisconnect() Exit Sub End If ReDim state.buffer(50000) client.BeginReceive(state.buffer, 0, state.BufferSize, 0, AddressOf sockDataArrival, state) RaiseEvent onDataArrival(Data, bytesRead) Catch RaiseEvent onError(Err.Description) Exit Sub End Try End Sub Any Idea about this.....?  Dheeraj PK http://dheerajpk.spaces.live.com/default.aspx

SSAS: An operation on a socket could not be performed...

Here is the scenario:  SSRS report in DEV, issues query that spins up Memory big time on SSAS.  MsmDSrv showing 1+ GBs Memory usage in Task Manager. After the connection is terminated, SSAS Service gets cycled.  At that point, can connect via SSMS from another server to this SSAS server. However when connecting from local SSMS, receive this error:  A connection cannot be made.  Eusure that the servier is running (admodClient).  An operation on a socket could not be performed because the system lacked sufficient buffer space or becasue a queue was full I really tried to find root cause - network trace, tcpview, vmmap, cycle SSAS, cycle SQL (shouldn't be related, but hey..) - but to no avail.  I'd love to be able to fix this without bouncing the server. SQL version 10.0.2531 SP1 x64, Windows 2008 R2 Enterprise.  Ideas?  Booting server now, but would looooove to have a non-boot solution to this

problem in socket connection

I had client and Server application, the server application to listern an a particular port. 500 clients are to connected and send the data to process everything fine.  At particular time i closed all clients and also close the server. when i start server after 10 mins at before 2 mins start all clients, very few clients(5-15) are connected. give me a solutiion.

C# Socket programming

Hi,       Im having a problem with some socket programming and im hoping someone here can help me. basically im trying to bind a listener to a port. I have used some source code i obtained from the net, however the code was a few years old and contained the obsolete "Dns.Resolve(string.Empty);" method to get the IPHostEntry information. Ive tried to replace this with "Dns.GetHostEntry(string.Empty);" however my code does not seem to be excuting past this point so im wondering if i have a logical error. this is the original method private void AcceptConnections() { IPHostEntry localMachineInfo; IPEndPoint localEndPoint; Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { localMachineInfo = Dns.Resolve(string .Empty); localEndPoint = new IPEndPoint(localMachineInfo.AddressList[0], _port); // Bind the listener socket to a local port listener.Bind(localEndPoint); // Set the socket in a 'listener' mode listener.Listen(10); // Continue accepting and processing new connections indefinitely while (true ) { threadEvent.Reset();

C# socket looping in response

Hi,   I'm getting data from a TCP server that sends bulk data in burst load. Can I use socket available property to loop in receiving data as below ? Or is it equivalent to peeking which is not recommended in winsock ? Thanks in advance and regards Navin --------------------------------------------------------- //to run loop m_bContinue = true;   int nReceivedBytes = 0;   int cntBytesRead = 0;   string m_strData = "";   StringBuilder sbData = new StringBuilder(); //Loop here while   (m_bContinue) { if   (!m_socket.Poll((Constants.SOCKET_POLL_TIMEOUT_MS % 1000) * 1000, SelectMode.SelectRead))   continue;     int cntAvailBytes = m_socket.Available;   if (cntAvailBytes > 0) {   arrBytesData = new byte[cntAvailBytes];   while (cntAvailBytes > 0) {   int nBytesToRead = cntAvailBytes; nReceivedBytes = m_socket.Receive(arrBytesData, nBytesToRead, SocketFlags.None);   if (nReceivedBytes > 0) {   //convert data from byte array to string   string data = System.Text.Encoding.UTF8.GetString(arrBytesData, 0, nReceivedBytes);   sbData.Append(data); cntAvailBytes -= nReceivedBytes;     }//while (cntAvailBytes >0 ) m_strData = sbData.ToString();

Bug in Socket.Connected property

Hi!I've built a server which is listening to port 55.I run the current code: (VB.NET) Code Block Imports System.NetImports System.Net.SocketsModule Module1    Sub Main()        Dim sck As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)        Dim myip As IPAddress = IPAddress.Parse("")        Dim myep As EndPoint = New IPEndPoint(myip, 55)        sck.Connect(myep)        Console.ReadKey() 'After this click I manually close the server        Console.WriteLine("Connected: {0}", Con(sck))        Console.ReadKey() 'Again...        Console.WriteLine("Connected: {0}", Con(sck))    End Sub    Public Function Con(ByRef Client As Socket) As Boolean        Try            Dim tmp(0) As Byte            client.Blocking = False            client.Send(tmp, 0, 0)        Catch e As SocketException            ' 10035 == WSAEWOULDBLOCK            If e.NativeErrorCode.Equals(10035) Then                Con = True            Else                Con = False            End If        End Try        Con = Client.Connected    End FunctionEnd Module As you can understand from the code, I connect to the server I've built, Waiting for the user to press 2 Enters in my program to show the state of the connection.It shows every Enter if the socket is connected (sck.Connected).So, I closed my server while they are connected, a

TCP Socket Test Tool

Hi folks: i'm in need of a way to troubleshoot an issue. My company uses a 3rd party Gateway application written in JBOSS (sneers, jibes, flaming comments) that is having communications issues. The 3rd party developer has been unable to determine WHY inbound TCP connections to their gateway application is failing. So what I wanted to do is either 1) write an app, or 2) utilize an existing app, that can create a generic TCP Listener on a IP:Port on the server, and a client TCP SENDER that can attempt to establish hundreds or thousands of simultaneous connection attemps, and transfer some meaningless data stream of a few hundred bytes. The 3rd party vendor is saying it's a server issue. So what I'd like to do is use a tool to verify that this application server (Windows 2003) can indeed sustain NNNN number of short lived inbound TCP connections. This isn't for THROUGHPUT testing of data transfer, but for the testing of the max number of simultaneous ESTABLISHED TCP Connections from clients. So it's kind of like a socket stress tool. For just a little more background, the 3rd party developer will not tell us how they've designed their thread pool and socket communications API. We suspect it has significant architectural flaws. So if we can use a tool to verify that the physical server and O/S can service thousands of TCP Socket communications of short length messages eith

Getting Error in Socket Programming...


I am creating one application with socket programming.
I am using visual studio 2008 with windows 7.
I am getting a error Message...

at line....



"No connection could be made because the target machine actively refused it"

class Class1{



void Main(string[] args)



IPAddress[] ipAddress = Dns

Socket issues



Let me apologise in advance for the length of this topic, but I'm struggling with this problem for a long time now.

I'm currently developing some components based upon the Socket class which is located in the System.Net.Sockets namespace of the .NET framework. I'm aware that there are more "ready" components available in that namespace, but that's beside the question here. I'm more interested in the problem i'm encountering and why this is happening in the first place. Perhaps I'm missing something, or I misunderstand the documentation of the components.

Here is the code for both the server & client component. They inherit from an interface that defines the public functions, so if you remove that from the class definition this code should compile on Visual Studio 2010 for those who wish to perform some tests.


  public class TCPClient : IClient
    public TCPClient(string address, int port)
      Address = address;
      Port = port;

    public TCPClient(Socket socket)
      m_socket = socket;
      Address = (socket.RemoteEndPoint 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend