Click here to Skip to main content
15,894,252 members
Home / Discussions / C#
   

C#

 
Questionseveral windows vs modal dialog Pin
koruyucu6-Nov-05 21:17
koruyucu6-Nov-05 21:17 
AnswerRe: several windows vs modal dialog Pin
Corinna John6-Nov-05 21:48
Corinna John6-Nov-05 21:48 
GeneralRe: several windows vs modal dialog Pin
koruyucu6-Nov-05 21:55
koruyucu6-Nov-05 21:55 
QuestionWeb Setup project Pin
manojk_batra6-Nov-05 20:06
manojk_batra6-Nov-05 20:06 
QuestionArray and ArrayList Pin
webC#6-Nov-05 20:01
webC#6-Nov-05 20:01 
AnswerRe: Array and ArrayList Pin
azazel006-Nov-05 20:24
azazel006-Nov-05 20:24 
GeneralRe: Array and ArrayList Pin
J4amieC6-Nov-05 21:48
J4amieC6-Nov-05 21:48 
Questionsocket connection problems Pin
g00fyman6-Nov-05 19:28
g00fyman6-Nov-05 19:28 
hi all,

can someone please tell me why this code fails at the while loop to get remote data, commented // ?? error here ??

i cant understand why it is failing, when i debug it, it pauses for about 5 seconds at the m_gatewaySocket.Receive(receiveBytes) line and returns 0 at this line, there fore breaking loop condition.

it is making the conneciton keep-alive when i test as well, dont know if this helps diagnosis much, cause i get same problem if i comment out the check for keep-alive.

sorry for all the code, syntax highlighting would be good on this forum Smile | :)

btw this is running in its own thread that is spawned from TcpListener.AcceptSocket()

<br />
Debug.WriteLine(" ------------- start request ----------------- ");<br />
      // get the bytes of the request<br />
      int bytes = ReadMessage(read, ref m_clientSocket, ref message);<br />
      if (bytes < 1)<br />
      {<br />
        return;<br />
      }<br />
      // get the address of the host in the request<br />
      HttpHeaderParser parser = new HttpHeaderParser(message);<br />
      uriString = parser.RequestUri;<br />
      host = parser.Host;<br />
<br />
      Debug.WriteLine("Connecting to: " + host);<br />
      Debug.WriteLine("Connection from: " + m_clientSocket.RemoteEndPoint);<br />
<br />
      // TODO: do checking for access to this address<br />
            <br />
      IPEndPoint gatewayEndPoint = new IPEndPoint(parser.AddressList[0] /*gatewayAddress*/, 80);<br />
      m_gatewaySocket = new Socket(m_clientSocket.AddressFamily, SocketType.Stream, ProtocolType.Tcp);<br />
<br />
      if (parser.KeepAlive)<br />
      {<br />
        m_gatewaySocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);<br />
      }      <br />
      m_gatewaySocket.Connect(gatewayEndPoint);<br />
<br />
      string output = "Connected to remote host: ";<br />
      output += (m_gatewaySocket.Connected) ? "OK" : "ERROR";<br />
      Debug.WriteLine(output);<br />
<br />
      // get the bytes of the request to send to remote host<br />
      byte[] bytesToSend = m_ascii.GetBytes(message);<br />
      // send the request<br />
      m_gatewaySocket.Send(bytesToSend); <br />
<br />
      // get the bytes of the response from the remote host<br />
      byte[] receiveBytes = new byte[4096];<br />
      // get the size of the response<br />
      int returnBytes = m_gatewaySocket.Receive(receiveBytes);<br />
<br />
      Debug.WriteLine("Received " +  returnBytes + " bytes from remote host");<br />
<br />
      // build the return page<br />
      string returnPage = m_ascii.GetString(receiveBytes);<br />
<br />
      while (returnBytes > 0)<br />
      {        <br />
        // ?? error here, next line returns 0 on first iteration ??<br />
        returnBytes = m_gatewaySocket.Receive(receiveBytes);<br />
        returnPage += m_ascii.GetString(receiveBytes);<br />
      }<br />
      <br />
      m_gatewaySocket.Shutdown(SocketShutdown.Both);<br />
      m_gatewaySocket.Close();<br />
<br />
      Debug.WriteLine(" ------------- end request ----------------- ");<br />


also if i test with site, www.google.com.au
the first call to int returnBytes = m_gatewaySocket.Receive(receiveBytes); that is before the while loop returns 1765 bytes as this
"HTTP/1.0 200 OK\r\nCache-Control: private\r\nContent-Type: text/html\r\nSet-Cookie: PREF=ID=56a9d4d131124690:TM=1131335053:LM=1131344693:IG=2:S=NKFaVbclxQhPNUPz; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com.au\r\nContent-Encoding: gzip\r\nServer: GWS/2.1\r\nContent-Length: 1363\r\nDate: Mon, 07 Nov 2005 06:24:53 GMT\r\nX-Cache: MISS from syd-nxg-pr3.tpgi.com.au\r\nProxy-Connection: keep-alive\r\n\r\n?

plus a whole lot more gibberish Smile | :)

kind regards,
g00fy
AnswerRe: socket connection problems Pin
g00fyman6-Nov-05 19:39
g00fyman6-Nov-05 19:39 
QuestionGUI: MySQL Administrator type navigation Pin
azazel006-Nov-05 19:20
azazel006-Nov-05 19:20 
AnswerRe: GUI: MySQL Administrator type navigation Pin
g00fyman6-Nov-05 19:36
g00fyman6-Nov-05 19:36 
AnswerRe: GUI: MySQL Administrator type navigation Pin
AETaylor6-Nov-05 20:41
AETaylor6-Nov-05 20:41 
GeneralRe: GUI: MySQL Administrator type navigation Pin
g00fyman6-Nov-05 21:36
g00fyman6-Nov-05 21:36 
GeneralRe: GUI: MySQL Administrator type navigation Pin
g00fyman6-Nov-05 22:52
g00fyman6-Nov-05 22:52 
AnswerRe: GUI: MySQL Administrator type navigation Pin
Michael P Butler6-Nov-05 21:53
Michael P Butler6-Nov-05 21:53 
Questionsaving and closing excel files in excel automation Pin
fox_mulder_fbi6-Nov-05 18:02
fox_mulder_fbi6-Nov-05 18:02 
QuestionC# Browser and Click link Event Handler Pin
takkung6-Nov-05 17:03
takkung6-Nov-05 17:03 
AnswerRe: C# Browser and Click link Event Handler Pin
S. Senthil Kumar6-Nov-05 19:07
S. Senthil Kumar6-Nov-05 19:07 
GeneralRe: C# Browser and Click link Event Handler Pin
takkung6-Nov-05 19:47
takkung6-Nov-05 19:47 
QuestionProblem with the PictureBox Control: Please Help Pin
E6AD6-Nov-05 13:43
E6AD6-Nov-05 13:43 
AnswerRe: Problem with the PictureBox Control: Please Help Pin
Christian Graus6-Nov-05 14:01
protectorChristian Graus6-Nov-05 14:01 
AnswerRe: Problem with the PictureBox Control: Please Help Pin
[Marc]6-Nov-05 15:18
[Marc]6-Nov-05 15:18 
QuestionInconsistent Accessibility error ? Pin
Christian Graus6-Nov-05 12:27
protectorChristian Graus6-Nov-05 12:27 
AnswerRe: Inconsistent Accessibility error ? Pin
Christian Graus6-Nov-05 12:29
protectorChristian Graus6-Nov-05 12:29 
Questionmemcpy in C# Pin
Christian Graus6-Nov-05 12:00
protectorChristian Graus6-Nov-05 12:00 

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.