Page 2 of 2

Posted: Fri Jun 24, 2005 2:21 pm
by jdubchak
Regarding the following snippet of code:

Code: Select all

wxMyServerThread* pThread =
new wxMyServerThread(this, pSocket);
Who's responsibility is it to delete the pointer to prevent a memory leak?


Posted: Fri Jun 24, 2005 7:20 pm
by Ryan Norton
jdubchak wrote:Who's responsibility is it to delete the pointer to prevent a memory leak?
As my comment mentions wx itself does so when the thread terminates (is there I way I can phrase it better perhaps?).

Client IP address in server

Posted: Fri Sep 16, 2005 2:30 pm
by Almeida
How to get the client IP address in server? In Windows API the server get the client address in accept():

Code: Select all

    SOCKET sd_listen, sd_accept;
    struct sockaddr_in addr_srv, addr_client;
    int size_addr, error;

    size_addr = sizeof(struct sockaddr_in);


    error = listen(sd_listen, SOMAXCONN);


    // Acceptting connection and getting client address.
    sd_accept = accept(sd_listen, (struct sockaddr*)&addr_client, &size_addr);

    // Printting client address.
    printf ("Accepted connection from client at %s.\n", inet_ntoa(addr_client.sin_addr));    
And in wxWindows? How to do it?


Posted: Fri Sep 16, 2005 2:46 pm
by upCASE
Use wxSocketBase::GetPeer();

Code: Select all

wxIPV4address adr;
wxString ip = adr.Hostname();

Posted: Tue Nov 29, 2005 10:44 pm
by GotenXiao
One thing that is currently bugging me is how to do a broadcast query...

For example, sending a few packets out on the broadcast address and asking for any servers. Said servers are listening and grab said packets and reply so the client knows where to go (similar, if not identical, to a server browser for, say, FEAR).

Ideally I'd like to keep it in wx calls, since resorting to raw WinSock calls would more than somewhat suck :/

[EDIT]Found this thread (, but it's not entirely clear on the code side. Anyone care to clarify a bit more, I'm struggling a bit :/

Posted: Wed Nov 30, 2005 9:46 am
by upCASE
Please start a new thread for that, as this thread is a FAQ and you should not post questions to it.

In the thread, refer to my code and specify what exactly troubles you :)
If I can, I'll comment on that.

Posted: Thu Jul 13, 2006 12:52 pm
by Peer Sommerlund
May I suggest this FAQ is merged into

This will have two bennefits:
1) Less confusion because there is only one source for wxSocket info
2) Faster to read because you don't have to go through the entire thread to make sure you did not miss some important points.

Well, with respect to 1) make that "one less source for wxSocket info" :)


Posted: Wed Aug 30, 2006 11:46 am
by fronda1
where is example to download?

Re: download?

Posted: Wed Aug 30, 2006 11:54 am
by upCASE
fronda1 wrote:where is example to download?
Example for what? wxSocket classes? Check the samples dir of the wxWidgets sources.

Posted: Thu Apr 17, 2008 1:39 am
by morya
Thx for the example.
mark here
so I am able to track this thread.

Posted: Mon Mar 23, 2009 3:49 am
by arust
How to using a thread for each server socket, like Multi Tab WebBrowser

Posted: Thu Dec 30, 2010 1:01 am
by hats
upCASE wrote:Hi!
Use wxSocketBase::GetPeer();

Code: Select all

wxIPV4address adr;
wxString ip = adr.Hostname();
Thanks a lot! I also have the same question.

Re: Sockets FAQ/Tutorial

Posted: Tue Dec 13, 2011 10:44 pm
by onionman
I find that my game just freezes unless I use the SOCKET_NOWAIT flag. Not sure what that's about, but this post would have really helped me out back when, thank you!

There just aren't any good tutorials out there on using wxSockets with multiple clients.

Re: Sockets FAQ/Tutorial

Posted: Fri Dec 16, 2011 8:39 pm
by Lord Asriel
This might be a good FAQ, but it is in no way a tutorial. It is meant to take people that know at least 40% of the subject to higher knowledge areas. However, people with 1% like me stand no chance. So, could you plase elaborate more OR point me to the right direction?

I tried one of the links suggested on the end of the first posts, but after getting some (interesting and usuful indeed) information, it started demonstrating the use of the winsock library functions, which I do not need to learn since I'm going to use wxSocket, which is a different thing, right?

Just to understand sockets, I am planning to make a chat program, the simplest thing I can think of: one input and one output text control, a send button, a create server button, and a join server button that spawns a dialog to set the ip and port. Am I thinking right? Please give me as much info as you can! Ready code would be appreciated (hope that doesn't present me as student-requesting-homework...)

Re: Sockets FAQ/Tutorial

Posted: Thu Aug 10, 2017 4:51 am
by sapthagiri
Hi Team,
I was just reading the posts related to wxsockets flag : ... ocketFlags

Observed that in some of the sample applications during socket creation or before socket send/recv() operations, they are setting wxsocket flags, please find the following enumerator:
wxSOCKET_NONE -> Normal functionality.
wxSOCKET_NOWAIT -> Read/write as much data as possible and return immediately.
wxSOCKET_WAITALL -> Wait for all required data to be read/written unless an error occurs.
wxSOCKET_BLOCK -> Block the GUI (do not yield) while reading/writing data.
wxSOCKET_REUSEADDR -> Allows the use of an in-use port.
wxSOCKET_BROADCAST -> Switches the socket to broadcast mode.
wxSOCKET_NOBIND -> Stops the socket from being bound to a specific adapter (normally used in conjunction with wxSOCKET_BROADCAST)
wxSOCKET_NOWAIT_READ -> Read as much data as possible and return immediately.
wxSOCKET_WAITALL_READ -> Wait for all required data to be read unless an error occurs.
wxSOCKET_NOWAIT_WRITE -> Write as much data as possible and return immediately.
wxSOCKET_WAITALL_WRITE -> Wait for all required data to be written unless an error occurs.

As per understanding the above flags are customized for wxWidgets platform or environment.
My query is do we have similar socket flags available in the Linux or Unix platform.
Browsed few forums & found that :
setsockopt(): passing flags such as SO_REUSEADDR or SO_BROADCAST etc..

Thanks & Regards,