Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Socket issues

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Socket issues
#3020
Posted by: lea 2003-11-29 02:42:27
With the follwing code i am unable to get a connection, the message is always "Failed ! Unable to connect", what did i wrong?


wxIPV4address addr;
   if(!addr.Hostname("localhost")) {
        messageField->AppendText(_("No host"));
        return;
   }
    if(!addr.Service(2810)) {
        messageField->AppendText(_("No service"));
        return;
   }
  
   wxSocketClient *m_sock = new wxSocketClient();
   m_sock->Connect(addr, true);
  
   if (m_sock->IsConnected())
     messageField->AppendText(_("Succeeded ! Connection establishedn"));
   else
   {
     m_sock->Close();
     messageField->AppendText(_("Failed ! Unable to connectn"));    
   }
  
   delete m_sock;

Another question, when i have an url like "http://www.google.com", how could i get the i address or host name to connect me with the server(when the server allows it)?

Thx in advance!
Message2. Re: Socket issues
#3021
Posted by: lea 2003-11-29 03:07:17
The error is an wxSOCKET_IOERR, what could that mean?

And with
 m_sock->Connect(addr, false);
 m_sock->WaitOnConnect(100);
it is an wxSOCKET_WOULDBLOCK.



Post Edited (11-29-03 03:09)
Message3. Re: Socket issues
#3023
Posted by: 2003-11-29 04:47:47
Well I havn't got around to digging into wxsockets to much yet, but
What have got listening on that port? I didn't recognise it, the well know ports lists it as 'Active Net Steward'. wxIPv4address seems to take care of DNS lookups its self, so just give it the domain name instead of a host address.
Message4. Re: Socket issues
#3024
Posted by: lea 2003-11-29 05:36:51
Well, thx!
I am a bit in shame, because...hm, no one was waiting on port 2810.
So the problem is solved:).
The domain the working,too.

Ok, shame on me and thx to you.
Message5. Re: Socket issues
#3025
Posted by: lea 2003-11-29 05:53:25
Adam, do you know how to send a post stream to a server?
Is it just to open the address with the domain at port 80 and to send a valid post stream?
Message6. Re: Socket issues
#3031
Posted by: 2003-11-30 23:04:15
Yes, more or less, use POST in the request line and add "Content-Length" and "Content-Type" fields to your header. You'll probably want to use wxURL::ConvertToValidURI() on the post data, eg:

POST /scripts/php/datareceive.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: wxWindows Application 1.0
Host: www.domain.com
Content-Length: 29

a=67&b=post&c=yes&d=take+away
Have you got a copy of the HTTP specs? There's one here http://www.ietf.org/rfc/rfc2068.txt
Message7. Re: Socket issues
#3032
Posted by: 2003-11-30 23:14:51
The forum screwed up, there's obviously a double new line before the body.
Message8. Re: Socket issues
#3033
Posted by: lea 2003-11-30 23:16:53
thx:-)
Message9. Re: Socket issues
#3034
Posted by: lea 2003-11-30 23:41:11
I just read in the rfc's the the server will answer with a code to my request.
(202, 404, etc)
At which port does he this?  At 80? How can i wait on port 80 then it is protected...



Post Edited (11-30-03 23:44)
Message10. Re: Socket issues
#3036
Posted by: 2003-12-01 05:22:03
You don't need another connection, the server replies down the same connection as you sent the request.

Generally you;
Open connection,
Make Request,
Wait for Reply (Readable),
Read Reply.

The server will then close the connection (usually ignoring any keep-alive request). This connection is handled below at the TCP/IP layer.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2023-2-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0