Guidance Forums / wxWidgets (wxWindows) in C++ / Socket issues

Search 搜索
Home Home

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Socket issues
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"));
    if(!addr.Service(2810)) {
        messageField->AppendText(_("No service"));
   wxSocketClient *m_sock = new wxSocketClient();
   m_sock->Connect(addr, true);
   if (m_sock->IsConnected())
     messageField->AppendText(_("Succeeded ! Connection establishedn"));
     messageField->AppendText(_("Failed ! Unable to connectn"));    
   delete m_sock;

Another question, when i have an url like "", 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
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);

Post Edited (11-29-03 03:09)
Message3. Re: Socket issues
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
Posted by: lea 2003-11-29 05:36:51
Well, thx!
I am a bit in shame,, 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
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
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
Content-Length: 29

Have you got a copy of the HTTP specs? There's one here
Message7. Re: Socket issues
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
Posted by: lea 2003-11-30 23:16:53
Message9. Re: Socket issues
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
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 • Refresh • New Topic • Search • Previous • Next First 1 Last
© Tue 2024-7-23  Guidance Laboratory Inc. Hits:0