473,473 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

About sockets. Receive methods

Hello. I'm using the socket class in an application and I use socket.receive
to wait for data. The problem is that the interface gets locked while the
receive method is executing.

I want to see the interface so the user knows what's happening at any time.

Is that possible?

--

Regards,

Diego F.

May 24 '07 #1
6 1408
You should put the socket code in another thread.

That way your GUI thread will be free to repaint and update while you are
looping / waiting to read from the socket.

I have not used sockets in dot net but that kinda a general rule to keep
things that loop alot off the GUI thread. Depending on how the sockets are
blocking or non blocking makes a diffrence but you might be able to put
application.doevents or ProcessMessagess or what ever makes the application
yeild to process windows messages. if you put that within your loop it
should help, but its a hack rather than a fix.

Mike.

"Diego F." <di********@msn.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Hello. I'm using the socket class in an application and I use
socket.receive to wait for data. The problem is that the interface gets
locked while the receive method is executing.

I want to see the interface so the user knows what's happening at any
time.

Is that possible?

--

Regards,

Diego F.

May 24 '07 #2
On May 24, 2:08 am, "Diego F." <diego_f...@msn.comwrote:
Hello. I'm using the socket class in an application and I use socket.receive
to wait for data. The problem is that the interface gets locked while the
receive method is executing.

I want to see the interface so the user knows what's happening at any time.

Is that possible?

--

Regards,

Diego F.
Diego,

Recieve is a synchronous socket operation, therefore it will block
until it recieves data or one of the endpoints is disconnected. You
have two choices if you don't like that behavior.

1) Manually spin off a separate thread of execution to perform you
socket operations.

2) Use the BeginXXX socket methods for asynchronous behavior.

IMHO, #2 is the far superior choice. You can find more information
about general usage of sockets in .net here:

http://msdn2.microsoft.com/en-us/library/b6xa24z5.aspx

Here is a specific article on asynchronous client sockets:

http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx

HTH

--
Tom Shelton

May 24 '07 #3
Thank you for your responses. I tried using a second thread, but then I
can't access the UI controls (I get an execution exception), so I'll try the
BeginAccept solution.

--

Regards,

Diego F.
"Diego F." <di********@msn.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Hello. I'm using the socket class in an application and I use
socket.receive to wait for data. The problem is that the interface gets
locked while the receive method is executing.

I want to see the interface so the user knows what's happening at any
time.

Is that possible?

--

Regards,

Diego F.

May 24 '07 #4
I'm thinking about the asynchronous solution, but, it will continue the code
in the main thread. I'm not sure that it works for me. The code after the
Receive, is for managing the sent data.

Do you see my problem? I'm migrating an old VB6 application, and it uses the
DataArrival event.

--

Regards,

Diego F.
"Diego F." <di********@msn.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Thank you for your responses. I tried using a second thread, but then I
can't access the UI controls (I get an execution exception), so I'll try
the BeginAccept solution.

--

Regards,

Diego F.
"Diego F." <di********@msn.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
>Hello. I'm using the socket class in an application and I use
socket.receive to wait for data. The problem is that the interface gets
locked while the receive method is executing.

I want to see the interface so the user knows what's happening at any
time.

Is that possible?

--

Regards,

Diego F.


May 24 '07 #5
On May 24, 8:40 am, "Diego F." <diego_f...@msn.comwrote:
I'm thinking about the asynchronous solution, but, it will continue the code
in the main thread. I'm not sure that it works for me. The code after the
Receive, is for managing the sent data.

Do you see my problem? I'm migrating an old VB6 application, and it uses the
DataArrival event.

--

Regards,

Diego F.

"Diego F." <diego_f...@msn.comwrote in message

news:%2****************@TK2MSFTNGP06.phx.gbl...
Thank you for your responses. I tried using a second thread, but then I
can't access the UI controls (I get an execution exception), so I'll try
the BeginAccept solution.
--
Regards,
Diego F.
"Diego F." <diego_f...@msn.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Hello. I'm using the socket class in an application and I use
socket.receive to wait for data. The problem is that the interface gets
locked while the receive method is executing.
I want to see the interface so the user knows what's happening at any
time.
Is that possible?
--
Regards,
Diego F.- Hide quoted text -

- Show quoted text -
The Async methods are based on callbacks, so it is going to be similar
to the way it works with the dataarival event, but with a little more
housekeeping.

By the way, either way - manual thread creation or the BeginXXX
methods, you will be unable to directly access the UI. Both methods
cause a thread creation, it's just using the async methods take care
of it and are very effiecient. So, you may want to look at this
series of articles on windows forms and multithreading:

http://msdn2.microsoft.com/en-us/library/ms951089.aspx

That's a link to the first part - but it is a 3 part article, so read
it all :)

The other option is to use the sync method, and use a backgroundworker
component... Or find a 3rd party component.

--
Tom Shelton
May 24 '07 #6
In terms of accessing the GUI from network threads i some times do this :

Hook the windows with the controls then when I want to update the GUI is use
POSTMESSAGE

This way the message is sent to the Window Loop which is hosting the GUI
controls, the Loop is running inside the GUI thread anyway so no access
violation occurs (accessing the controls via proxy).

If it is a complex control you can send your own message constant to the
main window loop like POSTMESSAGE(form1.hwnd, WM_LogConnection_Request, 0,
PointerToString)

then process this message

if Msg.Message = WM_LogConnection_Request then
ListBox1.Item.Add(Translated_String_from_pointer)

end if

"Diego F." <di********@msn.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Thank you for your responses. I tried using a second thread, but then I
can't access the UI controls (I get an execution exception), so I'll try
the BeginAccept solution.

--

Regards,

Diego F.
"Diego F." <di********@msn.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
>Hello. I'm using the socket class in an application and I use
socket.receive to wait for data. The problem is that the interface gets
locked while the receive method is executing.

I want to see the interface so the user knows what's happening at any
time.

Is that possible?

--

Regards,

Diego F.


May 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: jack | last post by:
At this link I have two c# projects, one is a client, the other is a server. Just point the ip address of the client at the server http://www.slip-angle.com/hosted/bug/ The server does...
3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
6
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
2
by: Dave | last post by:
Hi. I have an application that uses sockets, as per below: m_clientSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); int iPortNo =8000; IPEndPoint ipEnd =...
0
by: J008 | last post by:
Just looking for some insight as to why the callback "BeginReceiveFromCallback" is not being called in my "Receive" Subroutine below (when I call BeginReceiveFrom). I am trying to read data...
3
by: shahla.saeed | last post by:
hi, plzz check my code and let me know where the problem is lying...becuase whenever i try to tansfer the file of 573KB(mp3) it just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
7
by: | last post by:
I have the following program using System; using System.Collections; using System.Net.Sockets; using System.Net; using System.IO; public class Test { public static void Main(string s) {
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.