Click here to Skip to main content
15,125,968 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: imaging code; looking for optimization Pin
Daniel Grunwald30-Sep-05 23:56
MemberDaniel Grunwald30-Sep-05 23:56 
GeneralRe: imaging code; looking for optimization Pin
sarabjs3-Oct-05 7:30
Membersarabjs3-Oct-05 7:30 
Question.NET locking DLLs Pin
Gilad Kapelushnik27-Sep-05 0:48
MemberGilad Kapelushnik27-Sep-05 0:48 
Questiondrawing text on an image Pin
sarabjs26-Sep-05 6:30
Membersarabjs26-Sep-05 6:30 
AnswerRe: drawing text on an image Pin
Guido_d27-Sep-05 0:18
MemberGuido_d27-Sep-05 0:18 
GeneralRe: drawing text on an image Pin
Guido_d27-Sep-05 0:34
MemberGuido_d27-Sep-05 0:34 
GeneralRe: drawing text on an image Pin
sarabjs27-Sep-05 9:50
Membersarabjs27-Sep-05 9:50 
Question Strange behaviour with a System.Net.Sockets.Socket Pin
Guido_d26-Sep-05 4:53
MemberGuido_d26-Sep-05 4:53 
Hi,

Strange behaviour with a System.Net.Sockets.Socket, reproducable on 95, 2000
and XP

If I reuse a socket object after initializing it I can reconnect without
problems.

But

If the application has been running for 23 minutes or longer, the socket
will forever
wait for BeginConnect() to finish. Confused | :confused:

If I use a Connect() (also after 23 minutes) instead of async connecting the call will block
forever. OMG | :OMG:

I am using the following (pseudo) code to test. If running this after 23
minutes, the connect fails
and it is impossible to reconnect without restarting the application.

Is this known behaviour? Is there a workaround? Am I making a mistake? Help would be greatly
appreciated. For the time being I dropped a winsock control on a form and use that as my async socket.

regards

Guido

this is the offending code:
<br />
class SocketConnector<br />
{<br />
 AsyncCallback m_callback = null;<br />
 System.Net.Sockets.Socket m_socket = null;<br />
 bool m_connected = false;<br />
 public bool Connected<br />
 {<br />
  get { return m_connected; }<br />
 }<br />
 public void Connect(string ipaddress, int port)<br />
 {<br />
  // set up callback<br />
  m_callback = new AsyncCallback( OnConnect );<br />
<br />
  // create socket<br />
  m_socket = new Socket (AddressFamily.InterNetwork,SocketType.Stream <br />
,ProtocolType.Tcp );<br />
  m_socket.Blocking = false;<br />
<br />
  // get the remote IP address<br />
  IPAddress ip = IPAddress.Parse (ipaddress);<br />
  int iPortNo = System.Convert.ToInt16 ( port);<br />
<br />
  //create the end point<br />
  IPEndPoint ipEnd = new IPEndPoint (ip,iPortNo);<br />
<br />
  // begin async connect<br />
  IAsyncResult ar = m_socket.BeginConnect( ipEnd, m_callback, m_socket );<br />
<br />
  // wait for connect<br />
  ar.AsyncWaitHandle.WaitOne(2000,false);<br />
<br />
  if (!ar.IsCompleted || m_callback!=null)<br />
  {<br />
   // BeginConnect did not finish, breakpoint here to test<br />
   m_connected = false;<br />
   // ..<br />
   return;<br />
  }<br />
  // beginconnect finished OK<br />
  m_connected = true;<br />
 }<br />
 void OnConnect(IAsyncResult result)<br />
 {<br />
  m_callback = null;<br />
 }<br />
} <br />
<br />

QuestionWhat API can be used to access MS Project? Pin
kurdi1926-Sep-05 4:14
Memberkurdi1926-Sep-05 4:14 
QuestionXmlSerializer question Pin
Ivanets26-Sep-05 2:13
MemberIvanets26-Sep-05 2:13 
QuestionFind RichTextBox BackColor in VB.NET Pin
lupus canus26-Sep-05 0:56
Memberlupus canus26-Sep-05 0:56 
AnswerRe: Find RichTextBox BackColor in VB.NET Pin
lupus canus26-Sep-05 8:12
Memberlupus canus26-Sep-05 8:12 
QuestionIL and MSIL Pin
Rajesh_K_Sharma25-Sep-05 21:12
MemberRajesh_K_Sharma25-Sep-05 21:12 
AnswerRe: IL and MSIL Pin
Saqib Shakil25-Sep-05 22:28
MemberSaqib Shakil25-Sep-05 22:28 
AnswerRe: IL and MSIL Pin
Dave Kreskowiak26-Sep-05 4:09
mveDave Kreskowiak26-Sep-05 4:09 
Questioninformation regarding stack trace Pin
ravibabu_kanaparthi25-Sep-05 20:20
Memberravibabu_kanaparthi25-Sep-05 20:20 
Question.Net Application not Runing on Test System Pin
Zishan Haider25-Sep-05 5:19
MemberZishan Haider25-Sep-05 5:19 
AnswerRe: .Net Application not Runing on Test System Pin
Steve Pullan25-Sep-05 15:17
MemberSteve Pullan25-Sep-05 15:17 
GeneralRe: .Net Application not Runing on Test System Pin
Anonymous25-Sep-05 18:48
MemberAnonymous25-Sep-05 18:48 
GeneralRe: .Net Application not Runing on Test System Pin
Steve Pullan25-Sep-05 21:28
MemberSteve Pullan25-Sep-05 21:28 
GeneralRe: .Net Application not Runing on Test System Pin
Anonymous25-Sep-05 22:22
MemberAnonymous25-Sep-05 22:22 
Questionchar * = new char[] take me an ERROR!!!! Pin
firefoxrabbit24-Sep-05 4:35
Memberfirefoxrabbit24-Sep-05 4:35 
QuestionWhich is efficient. using &quot;&quot; or string.Empty? Pin
manivannan.p24-Sep-05 4:00
Membermanivannan.p24-Sep-05 4:00 
AnswerRe: Which is efficient. using &quot;&quot; or string.Empty? Pin
S. Senthil Kumar24-Sep-05 5:29
MemberS. Senthil Kumar24-Sep-05 5:29 
AnswerRe: Which is efficient. using &quot;&quot; or string.Empty? Pin
Member 230255124-Sep-05 6:17
MemberMember 230255124-Sep-05 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.