Cannot Receive More Than 1 Response With Async Sockets

Jun 16, 2009

I'm trying to setup an asynchronous client and I can send/receive one command and response, but when I try to send the second command, the command is sent (I verified by code inspection), but I am getting no response.

Heres the code, a majority of it is from the Microsoft example.

Option Explicit On
Imports System
Imports System.Net

[Code].....

View 1 Replies


ADVERTISEMENT

Async Sockets Client-server?

Jul 25, 2011

I'm using vb .net 2008 with 3.5 framework. (the following 2 classes are put in a DLL that i import in a main application)

Server class:

Code:
Imports System.Xml
Imports System.Net.Sockets
Imports System.Text
Imports System.Net

[code]....

Basically in my main application i am instantiating the client class from this dll, as well as the server one. On the client form i got a "send data" (SendFISA sub) and a "connect" button. After connecting the client and clicking on the "send data" i am sending to the server a string formed of some information created when instantiating the client class from the dll (i can't make that type of data public, but i'm just using a constructor to assign values to a class object, nothing special).

Now, when the server receives the data sent by "send data" button click it responds with "PKG_SENT" corresponding to the "FISASENT" string terminator(in the module) of the string that was sent. The "WRONG_MSG" constant is for when the string terminator is different from the 2 from above.

On the local disk, if the server cannot be reached, the client saves an xml file with this data. In the dll i made a timer that ticks every 5 seconds and checks to see if there is any xml file on the disk and sends it to the server if the connection is ok (trimiteXML sub). The server would respond with "XML_SENT" corresponding to the string terminator "XMLSENT"(in the module) appended to the read string from the xml file. After the file is sent it is deleted from the local dir.

The problem occurs when i click "send data" AND there are XML files to be sent from the disk. I believe they are interpreted by the server somehow at the same time because the message is neither "PKG_SENT" nor "XML_SENT", but it becomes a combination of the "WRONG_MSG_TYPE" and "XML_SENT", "XML_SENTG_TYPE". I have no idea why this is happening and i basically want the socket to wait with sending the files from the disks until the "send data" finishes.

View 9 Replies

Communications :: Async Sockets Reconnection?

Dec 17, 2008

Alright Simple question I got my main thread running Form Load and I make a socket then called BeginAcceptthen I pass AR to a Function that handles the Accept and creates a whole another sockets out of it and then loops for recv then when it gets everything closes then exits the functionbut how do I make the Socket from Form_Load run BeginAccept again to wait for another connection.. Do I call that command and Point it to the same Block thats Currently running, The block that Handles the AR Param??

View 3 Replies

Not Receiving All Packets - VB Sockets - Async?

Oct 27, 2009

Here's the code on the sending side of my sockets:

Private Sub Send(ByRef Buffer() As Byte)
Dim obj_StateObject As New StateObject
obj_StateObject.WorkSocket = m_tmpSocket

[code].....

View 1 Replies

VS 2010 Async Sockets Causing UI Update?

Apr 9, 2011

I'm using .BeginConnect with an AsyncCallBack and for some odd reason when I try to add a string to a textbox using the sub below, from a routine within the socket, it just does not work. It's not stating an invoke is required either.Private Delegate Sub DelegateAddText(ByRef theText As String, ByRef AddReturn As Boolean, ByRef AddPrefix As Boolean) Public Sub AddText(ByRef theText As String, ByRef AddReturn As Boolean, ByRef AddPrefix As Boolean)

[Code]...

as a side note which would be more efficient ... Indexing sockets and passing indexes through routines, or spawning classes. I realize spawning may use more memory but is it faster than indexing?

View 2 Replies

VS 2008 Async Socket Connections - Clear Out No Longer Useful Sockets From The Server?

Dec 18, 2009

I have been developing an async socket connection server and client program. I have been testing it, and noticed that if I connect to the server from my client and then disconnect. Upon reconnecting I am on a different port(local IP still). This is fine, however when I go to send a message, and the server trys to update all the clients, it eventually hits clients that do not exist anymore. I get the SocketException 10054, and upon connecting/disconnecting enough, it no longer works at all. My question is how do I clear out these no longer useful sockets from the server? I am doing currentsocket.Shutdown(SocketShutDown.Both); and then a currentsocket.Close(); after that. When a user disconnects.

[Code]...

View 1 Replies

Socket Async Send / Receive

Jan 5, 2012

I coded a small tcp server/client software implementing the async methods of the socket object. In order to keep track and control of the transfered data on both sides, I decided to wrap the bytes to be transfered into small 65 000 bytes packets, sent one after each other, in varying order.In most cases, it works perfectly, and it is impressively fast. However, when I want to transfer larger data than my usual requests, say like a dozen megabytes, crippling problems start to appear, out of shit.Effectively, it seems that somehow when executed without pauses, the server sends the packets too fast, or that the client receives it too slowly. However, if I put the SendAsync method's thread to sleep for like 100ms before sendingthe next packet, everything arrives without problem on the client.[code]

View 1 Replies

Sockets Command-response Timeout?

Jul 1, 2010

provide an example of a client server app using the System.Net.Sockets class that:

(a) supports multiple client connections

(b) that implements some sort of command-response timeout feature (by that I mean, once a client connects the server sends the client a message [e.g. Message A] and waits without blocking communication with other clients for a response. If a response is not received within a defined period it tries again perhaps and if there is still no response then it disconnects the client. If a response is received then it sends another message [e.g. Message B] and so on....Whilst this is going on the server must be able to accept connections from other clients).

If anybody has done something like this before and is willing to share their knowledge I'd be grateful. I've been trying for ages to get the timeout feature working correctly to no avail. I haven't posted what I have already because frankly it's a mess. I tried an ArrayList of timers (one for each client) that I started and stopped as messages were sent and received, but the timer elapsed event kept firing after I thought it should have stopped which may have something to do with the various threads involved with the asychronous communication I was trying to use (I really dont know).

It's really the server end that I'm having problems with because the client app only has to deal with messages coming from a single source. At this stage I don't care if it's done using synchronous or asychronous communication. I've trawled the web for every example I can find and but I can't find one that implements this kind of command-response timeout with multiple clients - i.e. most of them just show how to listen out (server) and connect (client) and how to send a message, i.e. there's no sequence of messages or timeouts.

View 4 Replies

Send / Receive Image Via Sockets

Feb 21, 2011

I want to send image from server to client via .net Sockets and assign it to a picturebox. but I got problem in receiving data, it's 'Server' side code:

[Code]...

View 7 Replies

Send And Receive Data Through Sockets?

Dec 3, 2008

I'm completely new to sockets etc.I'm trying to create an app that'll allow someone to send short information messages to several other people with the same app, using the internet and sockets(?)I've tried using code from online, but I'm getting no where.

View 4 Replies

Windows Service - Using Sockets To Send / Receive Data

Jul 27, 2009

I have written a windows service that uses sockets to send receive data, it works fine when the server has been running and all other services have started, but after a reboot it does not work. Now I know its probably dependant on another service and I know how to add dependencies, but how do I work out which services its dependent on?

View 1 Replies

Web Request To A 3rd Party And Receive The Response

Mar 2, 2011

I create a web page and i kept tht page in liver server. the page link in someurl/inboundmessage.aspx. in the page load i wrote the code request.querystring("Sender"). but this value is always returning blank I am using a 3rd party software to get the parameter . ther 3rd party software rule

[Code]...

View 1 Replies

Communications :: Socket Behaviour - Created A Client That Can Send And Receive Data Via TCP Sockets

Aug 26, 2010

I have created a Client that can send and receive data via TCP sockets. The objects stored on the serverside are the *exact* same object used for the client. They use the same send and receive protocols.

Now, when i send a string from the server to the client , it does precisely what it should do. However when I send a string to the server.... I do receive the string as an equal length of NULL characters. I run the server and client locally.

Basicly what can influence the behaviour between two completely identical objects performing the exact same task? I wonder if there is some socketflag issue if the TCPlistener.accept function returns a completely different setup then the one I R used to.

(if it is of any interest, the send protocol is asynchronious)

View 3 Replies

Send Post Request And Receive Response

Apr 6, 2011

When you search on google most of the examples are very vague, hopefully this thread can make it to the top and will help someone looking for the same info.to explain the code what it does is create a long string by concatenating all the values together stores it in the variable finalString and then hashes the string using the SHA5 algorithm. Then its supposed to send the string (finalString) as a post request to the url.The server im sending it to reads it this way and sends a response. [code]

View 1 Replies

Communications :: Used To Assemble And Send Raw Packet / Receive Response Packets?

Sep 14, 2008

What Visual Basic code can be used to assemble and send a raw packet, and receive response packets? I looked on MSDN and I couldn't find any documentation for anything used to send a packet.

View 2 Replies

Making An Async Function Not Async?

Jun 3, 2010

I'm trying to write a 'developer friendly' wrapper for the Windows API EnumWindows - the problem is that the API uses a callback function that gets invoked on another thread, where as I want my wrapper function to simplify this and make it more useful by working like any other normal synchronous function and just returning a value.

Now if the API just called the callback once that would be fine, as I would just call the API and make the wrapper function wait until it got a signal from the callback function telling it to continue... but the API calls the callback function over 100 times (once for every window handle that exists). The biggest problem is that there is nothing that indicates that any particular call to this callback function is the last one, so my wrapper function has no idea when it is safe to continue and return the list of window handles to the caller.

The only solution I could think of is to do this:

1. The wrapper function calls the API and starts a timer that waits 2 seconds before it raises the Elapsed event. The wrapper function then pauses until it receives a signal (ManualResetEvent)

2. Each time the callback function is raised by the API on a different thread, it stops the timer (so this is before the 2 seconds have elapsed), adds the current window handle that was passed in by the API to the list of handles, then starts the timer again.

3. If the timer reaches its 2 second interval then it is assumed that we are at the end of the windows because otherwise the callback would have stopped the timer. So the timer's Elapsed event handler is what signals the original thread (that the wrapper function is executing on) to continue as we now have a complete list of windows to return.

This works fine and does exactly what I want... but I dont like it.

I dont like forcing the caller to wait an extra 2 seconds after the API has done its last callback but more importantly I dont like assuming that the API will never take longer than 2 seconds between callbacks. In reality on my PC it is never anywhere near that long between callbacks, it is something like 200 miliseconds, but I have no idea how long it would be on a slower PC and I want this to be completely reliable.

[URL]

View 14 Replies

Server Response Was Successfully Sent To Client Without Client Response Back?

Apr 21, 2010

i made a tcp/ip application using the .NET TcpListener class, my problem is that sometimes (about 30 / 4000) the connection between the client and the server got interrupted in the middle and the server response to the client is lost.is there a way to know if the server response was successfully sent to the client without the client response back?

View 9 Replies

C# - Using Async Methods Asp.net?

Jul 15, 2010

I have two methods on the page. One AddMessageToInboxOutbox(params[]) and other one SendNewMessageMail(params[]).

Once user sends an message to other other first message is added to DB and then sent to recipient's email. Sometimes SMTP is heavy loaded and it takes up to 5 seconds to get answer from it. I want to enclose SendNewMessageMail(params[]) with async call using other thread or something. I have never done that.

How do i perform this action right in ASP.NET?

View 2 Replies

Wpf - Update UI Async?

Nov 3, 2011

[Code]...

In my scenario the Button_Click is a command delegate in the VM, and the Thread.Sleep is some long-running process (about 2-10 seconds). I want, that when the user calls the command, it should immediately update the UI disabling the button so the user cannot execute it while it's running, then execute that operation, then, when operation completed, unblock the button.

[Code]...

View 3 Replies

Async Callback From ThreadPool?

Jun 12, 2009

I have a bunch of operations that need to be executed simultaneously. For this I'm using the thread pool to execute the tasks. I'd like to know if it's possible to consume some sort of Async Callback (similar to BackgroundWorker.DoWorkComplete) when each thread is finished. The reasoning behind this is that I have a windows service running that uses IPC to update a GUI and I need to know the time at which each specific thread finishes I've used background workers to do a set of tasks and they work perfectly, however, they take longer than I would like. I've timed the execution on my BGW method for a designated number of said tasks and it took 27 seconds, and the same set of tasks takes 4 seconds using the threadpool method. I've also tried using managed threads, to the same effect as the background workers.

View 5 Replies

C# - .NET Async Lambda-expressions?

Apr 20, 2012

Async Sub like this: Dim f As Func(Of Task) = Async Sub() End Sub Produces compiler error: error BC36670: Nested sub does not have a signature that is compatible with delegate 'System.Func(Of System.Threading.Tasks.Task)'.Equivalent C# code compiles fine:

Func<Task> f = async () => { };Rewriting Async Sub into Async Function make code works.

Why does Async Sub() is not convertible to delegate types with return value of type Task?

View 1 Replies

How To Make WebRequest ASync

Oct 1, 2011

I think this is a simple question for you, but I don't understand other cases of webRequests, so I asked here: How can I make this webRequest asynchronous?
Dim sBuffer As String
Dim oRequest As WebRequest = WebRequest.Create(url)
oRequest.Method = "GET"
Dim oResponse As WebResponse = oRequest.GetResponse()
Dim oStream As New StreamReader(oResponse.GetResponseStream())
[Code] .....

View 1 Replies

Using Async CTP Await With Events?

Jul 15, 2011

Relevant to Silverlight 5 / Async CTP

I want to create an asynchronous function that initiates a layout update and then Awaits for the layout update to complete. Something like:

Private Async Function UpdateLayoutRoot() As Task
LayoutRoot.UpdateLayout()
Await LayoutRoot.LayoutUpdated <--- (NOT valid but shows desired outcome)
End Function

How can this be done? More generally, how can you use Await to wait for existing events?

View 2 Replies

Wpf - HttpWebRequest.BeginGetResponse Is Not Async?

Mar 31, 2011

I have some code that iterates a few 100 urls and requests the data from the web.It looks something like this

for each url in urls
Dim hwr = CType(WebRequest.Create(url), HttpWebRequest)
Dim rq = New ReqArgs

[code]....

How come the BeginGetresponse line takes about 2-3 seconds to complete before going to dim a=1?. Actually I debugged and I see that the FinishWebRequest procedure runs completely before the Dim a=1 is reached.So is this async?I'm not earning any time by using the async. am I? Or is there a different way to do this?The point is that the main sub should fire off 300 requests and return control to the UI, then the FinishWebRequest should process them slowly on its own thread and own time , as the requests come in.How do I do that?Btw, the main sub is running in a BackgroundWorker, but I checked with out the BackgroundWorker and the problem is the same?

View 1 Replies

.net - Using Task For Async Operation But UI Is Still Unresponsive

Jun 14, 2012

I have a WPF application in which i have to do a long running task (basically reading from network). Just to give you a snapshot I am doing the following thing on button click

Dim t As Task(Of String) = Task.Factory.StartNew(Of String)(Function()
'Thread.sleep is simulating long running task that will make UI unresponsive
Thread.Sleep(10000)

[Code].....

I cannot use Event based async methodology because the reading API actually exist in a dll which i refer in my program, that contains a function Public function ReadFromNetwork() as String. This API is making an async call to network to read a long string and return to UI. So, in short i m doing TextBlock1.Text = ExternalDll.ReadFromNetwork().

but the problem is that even if i use Task asynchrony, the UI is still unresponsive.

View 3 Replies

Async - Pinging All Computers In List

Nov 24, 2011

I've run into a bit of a problem using Async ping. Basically, I want to ping computers in the list before I run the next bit of my program. The computers who I can ping are added to a list and that is used in a background worker. Trouble is can't seem to work out how to wait until after pinging ALL computers in the list, either successful or timed-out. Is there something a long the lines of 'If Async Ping is running'?

Private Sub pingCompleted(ByVal sender As Object, ByVal e As System.Net.NetworkInformation.PingCompletedEventArgs)
If e.Reply.Status = Net.NetworkInformation.IPStatus.Success Then
complist.Add(e.UserState)
Else
'do nothing
End If
End Sub

I need the next bit to wait because if 'complist' is changed while it's being used I get collection errors.

View 7 Replies

Async Connect From VB 6 To VB 2008 Express

Dec 21, 2009

I am working on moving a project from VB6 to VB 2008 Express. [Code] When I connect to mysql db in VB6, I connect using adAsynConnect. This way, I have a "Loading..." animation display while a connection is attempted. Is there a way to do this in 2008 Express? Or something similar I could read up on?

View 4 Replies

Async Web Service Call Within Console App

Nov 24, 2009

I have a console app that is supposed to async call a web service...i don't get any errors but the completed handler doesn't seem to complete correctly. I have a subroutine with a loop that is supposed to fire off say 6 seperate calls to another routine that calls the service. The completed event handler routine puts data into the database..If i put a thread.sleep under the call to the routine calling the web service. The completed event handler fires but only one record is put in the database instead of the hundreds expected and only that one webservice call appears to fire.I should mention that this works as expected when calling the sync method of the web service within a console app and the asyc calls work as expected from a windows forms app. I just need it to work async within a console app..

View 1 Replies

Clean Up App And Deal With The Async Calls?

Mar 16, 2010

My app is basically talking to a device via RS232. I need to 'listen' to the data received and do certain things based on it, update labels, etc. When I started, I only had a couple cross-thread calls and I used JMC's example to get by that. Now my app is bigger and I am calling the ThreadProcSafe all the time. I am hoping there is an easier way so I don't have to create sub routines for every control. Here's the relevant parts of my code.

Private Sub StepperSerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles StepperSerialPort.DataReceived
Dim ReceiveBuffer As String

[Code].....

View 4 Replies

Picturebox Async Load Not Complete?

Dec 12, 2011

i load the images in my project, using the load async method, but sometime, the picturebox doesn't show the image loaded, but only, the default not complete load image preview (red, blue and green geometric forms).

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved