* Added wxsocket lib and sample (I hope I don't forget some file)
* Updated some wx data and makefiles * Updates on wxStream (reorganization) makefile for Windows will nearly follow wxSocket should work on wxGTK (I've tested it) * IPC over Network is included git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@684 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
1
samples/wxsocket/Makefile
Normal file
1
samples/wxsocket/Makefile
Normal file
@@ -0,0 +1 @@
|
||||
include ../../setup/general/makeapp
|
28
samples/wxsocket/Makefile.in
Normal file
28
samples/wxsocket/Makefile.in
Normal file
@@ -0,0 +1,28 @@
|
||||
# WXXT base directory
|
||||
WXBASEDIR=@WXBASEDIR@
|
||||
|
||||
# set the OS type for compilation
|
||||
OS=@OS@
|
||||
# compile a library only
|
||||
RULE=bin2
|
||||
|
||||
# define library name
|
||||
BIN_TARGET=client
|
||||
BIN2_TARGET=server
|
||||
# define library sources
|
||||
BIN_SRC= client.cpp
|
||||
BIN2_SRC= server.cpp
|
||||
|
||||
#define library objects
|
||||
BIN_OBJ= client.o
|
||||
BIN2_OBJ= server.o
|
||||
|
||||
# additional things needed to link
|
||||
BIN_LINK=
|
||||
BIN2_LINK=
|
||||
|
||||
# additional things needed to compile
|
||||
ADD_COMPILE=
|
||||
|
||||
# include the definitions now
|
||||
include ../../../template.mak
|
281
samples/wxsocket/client.cpp
Normal file
281
samples/wxsocket/client.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* File: client.cpp
|
||||
* Purpose: wxSocket: client demo
|
||||
* Author: LAVAUX Guilhem (from minimal.cc)
|
||||
* Created: June 1997
|
||||
* Updated:
|
||||
* Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
* (C) 1997, LAVAUX Guilhem
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "wx/socket.h"
|
||||
#include "wx/url.h"
|
||||
#include "wx/protocol/http.h"
|
||||
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
{ public:
|
||||
virtual bool OnInit(void);
|
||||
};
|
||||
|
||||
class MyClient;
|
||||
|
||||
// Define a new frame type
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
DECLARE_CLASS(MyFrame)
|
||||
public:
|
||||
MyClient *sock;
|
||||
|
||||
MyFrame(void);
|
||||
virtual ~MyFrame();
|
||||
void OnCloseTest(wxCommandEvent& evt);
|
||||
void OnExecTest1(wxCommandEvent& evt);
|
||||
void OnExecUrlTest(wxCommandEvent& evt);
|
||||
void OnQuitApp(wxCommandEvent& evt);
|
||||
void OnExecOpenConnection(wxCommandEvent& evt);
|
||||
void OnExecCloseConnection(wxCommandEvent& evt);
|
||||
void UpdateStatus();
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_CLASS(MyFrame, wxFrame)
|
||||
|
||||
/*
|
||||
* Define a new derived SocketClient
|
||||
*/
|
||||
class MyClient: public wxSocketClient
|
||||
{
|
||||
public:
|
||||
MyFrame *frame;
|
||||
|
||||
void OnNotify(wxRequestNotify WXUNUSED(flags)) { frame->UpdateStatus(); }
|
||||
};
|
||||
|
||||
// ID for the menu quit command
|
||||
const SKDEMO_QUIT = 101;
|
||||
const SKDEMO_CONNECT = 102;
|
||||
const SKDEMO_TEST1 = 103;
|
||||
const SKDEMO_TEST2 = 104;
|
||||
const SKDEMO_CLOSE = 105;
|
||||
const SKDEMO_TEST3 = 106;
|
||||
const ID_TEST_CLOSE = 107;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
/*
|
||||
* `Main program' equivalent, creating windows and returning main app frame
|
||||
*/
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
// Create the main frame window
|
||||
MyFrame *frame = new MyFrame();
|
||||
|
||||
// Give it an icon
|
||||
#ifdef wx_msw
|
||||
frame->SetIcon(new wxIcon("mondrian"));
|
||||
#endif
|
||||
#ifdef wx_x
|
||||
frame->SetIcon(new wxIcon("mondrian.xbm"));
|
||||
#endif
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu();
|
||||
|
||||
file_menu->Append(SKDEMO_QUIT, "Exit");
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
menu_bar->Append(file_menu, "File");
|
||||
|
||||
wxMenu *socket_menu = new wxMenu();
|
||||
socket_menu->Append(SKDEMO_CONNECT, "Open session");
|
||||
socket_menu->AppendSeparator();
|
||||
socket_menu->Append(SKDEMO_TEST1, "Start test 1");
|
||||
socket_menu->Append(SKDEMO_TEST2, "Start test 2");
|
||||
socket_menu->AppendSeparator();
|
||||
socket_menu->Append(SKDEMO_CLOSE, "Close session");
|
||||
socket_menu->AppendSeparator();
|
||||
socket_menu->Append(SKDEMO_TEST3, "Start URL test");
|
||||
|
||||
menu_bar->Append(socket_menu, "Socket");
|
||||
|
||||
frame->SetMenuBar(menu_bar);
|
||||
|
||||
// Make a panel with a message
|
||||
(void)new wxPanel(frame, 0, 0, 300, 100);
|
||||
|
||||
// Show the frame
|
||||
frame->Show(TRUE);
|
||||
|
||||
// Return the main frame window
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* MyFrame Constructor
|
||||
*/
|
||||
MyFrame::MyFrame():
|
||||
wxFrame(NULL, -1, "wxSocket client demo",
|
||||
wxDefaultPosition, wxSize(300, 200), wxDEFAULT_FRAME_STYLE)
|
||||
{
|
||||
// Init all
|
||||
wxSocketHandler::Master();
|
||||
|
||||
sock = new MyClient();
|
||||
sock->SetFlags(wxSocketBase::WAITALL);
|
||||
wxSocketHandler::Master().Register(sock);
|
||||
sock->frame = this;
|
||||
sock->SetNotify(wxSocketBase::REQ_LOST);
|
||||
CreateStatusBar(2);
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
MyFrame::~MyFrame()
|
||||
{
|
||||
delete sock;
|
||||
}
|
||||
|
||||
void MyFrame::OnQuitApp(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
Close(TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::OnExecOpenConnection(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
wxIPV4address addr;
|
||||
|
||||
if (sock->IsConnected())
|
||||
sock->Close();
|
||||
|
||||
wxString hname = wxGetTextFromUser("Enter the address of the wxSocket Sample Server",
|
||||
"Connect ...", "localhost");
|
||||
addr.Hostname(hname);
|
||||
addr.Service(3000);
|
||||
sock->SetNotify(0);
|
||||
sock->Connect(addr, TRUE);
|
||||
if (!sock->IsConnected())
|
||||
wxMessageBox("Can't connect to the specified host", "Alert !");
|
||||
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
void MyFrame::OnExecCloseConnection(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (sock)
|
||||
sock->Close();
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_BUTTON(ID_TEST_CLOSE, MyFrame::OnCloseTest)
|
||||
EVT_MENU(SKDEMO_TEST1, MyFrame::OnExecTest1)
|
||||
EVT_MENU(SKDEMO_TEST3, MyFrame::OnExecUrlTest)
|
||||
EVT_MENU(SKDEMO_QUIT, MyFrame::OnQuitApp)
|
||||
EVT_MENU(SKDEMO_CONNECT, MyFrame::OnExecOpenConnection)
|
||||
EVT_MENU(SKDEMO_CLOSE, MyFrame::OnExecCloseConnection)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
void MyFrame::OnCloseTest(wxCommandEvent& evt)
|
||||
{
|
||||
wxButton *button = (wxButton *)evt.GetEventObject();
|
||||
wxDialog *dlg = (wxDialog *)button->GetParent();
|
||||
|
||||
dlg->EndModal(0);
|
||||
}
|
||||
|
||||
void MyFrame::UpdateStatus()
|
||||
{
|
||||
if (!sock->IsConnected()) {
|
||||
SetStatusText("Not connected", 0);
|
||||
SetStatusText("", 1);
|
||||
} else {
|
||||
wxIPV4address addr;
|
||||
char s[100];
|
||||
|
||||
sock->GetPeer(addr);
|
||||
sprintf(s, "Connected to %s", (const char *)addr.Hostname());
|
||||
SetStatusText(s, 0);
|
||||
sprintf(s, "Service: %d", addr.Service());
|
||||
SetStatusText(s, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!sock->IsConnected())
|
||||
return;
|
||||
|
||||
wxDialog *dlgbox = new wxDialog(this, -1, "Test 1", wxDefaultPosition, wxSize(410, 270));
|
||||
wxTextCtrl *text_win = new wxTextCtrl(dlgbox, -1, "",
|
||||
wxPoint(0, 0), wxSize(400, 200),
|
||||
wxTE_MULTILINE);
|
||||
(void)new wxButton(dlgbox, ID_TEST_CLOSE, "Close",
|
||||
wxPoint(100, 210), wxSize(100, 40));
|
||||
char *buf, *buf2;
|
||||
|
||||
dlgbox->Layout();
|
||||
dlgbox->Show(TRUE);
|
||||
|
||||
text_win->WriteText("Initializing test 1 ...\n");
|
||||
|
||||
/* Init */
|
||||
buf = copystring("Salut ! Salut ! Salut ! Salut Toto\n");
|
||||
buf2 = new char[strlen(buf)+1];
|
||||
char c = 0xbe;
|
||||
sock->WriteMsg(&c, 1);
|
||||
|
||||
/* No 1 */
|
||||
text_win->WriteText("Sending some byte to the server ...");
|
||||
sock->Write(buf, strlen(buf)+1);
|
||||
text_win->WriteText("done\n");
|
||||
text_win->WriteText("Receiving some byte from the server ...");
|
||||
sock->Read(buf2, strlen(buf)+1);
|
||||
text_win->WriteText("done\n");
|
||||
|
||||
text_win->WriteText("Comparing the two buffers ...");
|
||||
if (memcmp(buf, buf2, strlen(buf)+1) != 0) {
|
||||
text_win->WriteText("Fail\n");
|
||||
sock->Close();
|
||||
UpdateStatus();
|
||||
} else
|
||||
text_win->WriteText("done\nTest 1 passed !\n");
|
||||
|
||||
dlgbox->Layout();
|
||||
dlgbox->ShowModal();
|
||||
|
||||
delete [] buf;
|
||||
delete [] buf2;
|
||||
delete text_win;
|
||||
delete dlgbox;
|
||||
}
|
||||
|
||||
void MyFrame::OnExecUrlTest(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
wxString urlname = wxGetTextFromUser("Enter the address of the wxSocket Sample Server",
|
||||
"Connect ...", "localhost");
|
||||
|
||||
wxURL url(urlname);
|
||||
wxInputStream *datas = url.GetInputStream();
|
||||
|
||||
if (!datas)
|
||||
wxMessageBox("Error in getting data from the URL.", "Alert !");
|
||||
else {
|
||||
wxMessageBox("Success !!", "OK !");
|
||||
delete datas;
|
||||
}
|
||||
}
|
8
samples/wxsocket/client.def
Normal file
8
samples/wxsocket/client.def
Normal file
@@ -0,0 +1,8 @@
|
||||
NAME Client
|
||||
DESCRIPTION 'Client'
|
||||
EXETYPE WINDOWS
|
||||
STUB 'WINSTUB.EXE'
|
||||
CODE PRELOAD MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE MULTIPLE
|
||||
HEAPSIZE 1024
|
||||
STACKSIZE 8192
|
3
samples/wxsocket/client.rc
Normal file
3
samples/wxsocket/client.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON mondrian.ico
|
||||
conn_icn ICON connect.ico
|
||||
#include "wx.rc"
|
BIN
samples/wxsocket/connect.ico
Normal file
BIN
samples/wxsocket/connect.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
86
samples/wxsocket/makefile.b32
Normal file
86
samples/wxsocket/makefile.b32
Normal file
@@ -0,0 +1,86 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Patrick Halke, modified by Guilhem Lavaux
|
||||
# Created: 1997
|
||||
# Updated:
|
||||
# Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds 32bit wxstring library for Windows 3.1
|
||||
# and Borland C++ 4.x
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
!include $(WXDIR)\src\makeb32.env
|
||||
|
||||
WXLIBDIR = $(WXDIR)\lib
|
||||
WXLIB = $(WXDIR)\lib\wx32.lib
|
||||
SOCKETLIB = $(WXDIR)\lib\wxsocket.lib $(WXDIR)\lib\zlib.lib
|
||||
WXINC = $(WXDIR)\include\msw
|
||||
WXBASESRC = $(WXDIR)\src\base
|
||||
WXBASEINC = $(WXDIR)\include\base
|
||||
LIBS=$(WXLIB) $(SOCKETLIB) cw32 import32
|
||||
|
||||
!ifndef DEBUG
|
||||
DEBUG=0
|
||||
!endif
|
||||
|
||||
!if "$(FINAL)" == "0"
|
||||
LINKFLAGS=/v /Tpe /L$(WXLIBDIR);$(BCCDIR)\lib
|
||||
OPT = -Od
|
||||
DEBUG_FLAGS= -v -DDEBUG=$(DEBUG)
|
||||
!else
|
||||
LINKFLAGS=/Tpe /L$(WXLIBDIR);$(BCCDIR)\lib
|
||||
OPT = -O2
|
||||
DEBUG_FLAGS = -DDEBUG=$(DEBUG)
|
||||
!endif
|
||||
|
||||
CPPFLAGS=$(DEBUG_FLAGS) $(OPT) @$(CFG)
|
||||
|
||||
CLIENT_TARGET=client
|
||||
SERVER_TARGET=server
|
||||
CLIENT_OBJECTS=client.obj
|
||||
SERVER_OBJECTS=server.obj
|
||||
|
||||
.c.obj:
|
||||
bcc32 $(CPPFLAGS) -P- -c {$< }
|
||||
|
||||
all: $(CLIENT_TARGET).exe $(SERVER_TARGET).exe
|
||||
|
||||
$(CLIENT_TARGET).exe: $(CLIENT_OBJECTS) $(CLIENT_TARGET).def $(CLIENT_TARGET).res
|
||||
tlink32 $(LINKFLAGS) @&&!
|
||||
c0w32.obj $(CLIENT_OBJECTS)
|
||||
$(CLIENT_TARGET)
|
||||
nul
|
||||
$(LIBS)
|
||||
$(CLIENT_TARGET).def
|
||||
!
|
||||
brc32 -K $(CLIENT_TARGET).res
|
||||
|
||||
client.obj: client.cpp
|
||||
|
||||
$(CLIENT_TARGET).res : $(CLIENT_TARGET).rc $(WXDIR)\include\msw\wx.rc
|
||||
brc32 -r /i$(BCCDIR)\include /i$(WXDIR)\include\msw /i$(WXDIR)\contrib\fafa $(CLIENT_TARGET)
|
||||
|
||||
$(SERVER_TARGET).exe: $(SERVER_OBJECTS) $(SERVER_TARGET).def $(SERVER_TARGET).res
|
||||
tlink32 $(LINKFLAGS) @&&!
|
||||
c0w32.obj $(SERVER_OBJECTS)
|
||||
$(SERVER_TARGET)
|
||||
nul
|
||||
$(LIBS)
|
||||
$(SERVER_TARGET).def
|
||||
!
|
||||
brc32 -K $(SERVER_TARGET).res
|
||||
|
||||
server.obj: server.cpp
|
||||
|
||||
$(SERVER_TARGET).res: $(SERVER_TARGET).rc $(WXDIR)\include\msw\wx.rc
|
||||
brc32 -r /i$(BCCDIR)\include /i$(WXDIR)\include\msw /i$(WXDIR)\contrib\fafa $(SERVER_TARGET)
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase *.exe
|
||||
-erase *.res
|
||||
-erase *.map
|
||||
-erase *.rws
|
75
samples/wxsocket/makefile.g95
Normal file
75
samples/wxsocket/makefile.g95
Normal file
@@ -0,0 +1,75 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Stefan Hammes
|
||||
# Created: 1995
|
||||
# Updated:
|
||||
# Copyright: (c) 1995
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for wxString example (UNIX).
|
||||
# Change the WXDIR directory, and CPPFLAGS and LDFLAGS, for your system.
|
||||
|
||||
WXDIR = ../..
|
||||
|
||||
# All common UNIX compiler flags and options are now in
|
||||
# this central makefile.
|
||||
include $(WXDIR)/src/makeg95.env
|
||||
|
||||
WXSOCKDIR = $(WXDIR)/contrib/wxsock
|
||||
WXSOCKLIB = $(WXSOCKDIR)/libwxsock.a
|
||||
|
||||
OBJECTS = $(OBJDIR)/wx_sock.$(OBJSUFF) $(OBJDIR)/wx_addr.$(OBJSUFF) \
|
||||
$(OBJDIR)/wx_pkman.$(OBJSUFF) $(OBJDIR)/wx_skflt.$(OBJSUFF) \
|
||||
$(OBJDIR)/wx_lzw.$(OBJSUFF) \
|
||||
$(OBJDIR)/wx_url.$(OBJSUFF) $(OBJDIR)/wx_ftp.$(OBJSUFF) \
|
||||
$(OBJDIR)/wx_file.$(OBJSUFF) $(OBJDIR)/wx_nipc.$(OBJSUFF) \
|
||||
$(OBJDIR)/wx_wipc.$(OBJSUFF) $(OBJDIR)/wx_sipc.$(OBJSUFF)
|
||||
|
||||
TESTOBJECTS = $(OBJDIR)/test.$(OBJSUFF)
|
||||
TESTPROGRAM = $(WXSTRINGDIR)/test$(GUISUFFIX)
|
||||
|
||||
LDFLAGS = $(XLIB) -L$(WXSOCKDIR) -L$(WXDIR)/lib
|
||||
|
||||
XVIEWLDLIBS = -lwxstring_ol -lwx_ol -lxview -lolgx -lX11 -lm $(COMPLIBS)
|
||||
MOTIFLDLIBS = -lwxstring_motif -lwx_motif -lXm -lXt -lX11 -lm $(COMPLIBS)
|
||||
HPLDLIBS = -lwxstring_hp -lwx_hp -lXm -lXt -lX11 -lm $(HPCOMPLIBS)
|
||||
# Default
|
||||
LDLIBS=$(MOTIFLDLIBS)
|
||||
|
||||
all: $(OBJDIR) $(WXSOCKLIB)
|
||||
|
||||
demo: $(TESTPROGRAM)
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
# Comment this out if 'say' doesn't speak on your system, or make it beep perhaps!
|
||||
done:
|
||||
say dun
|
||||
|
||||
wx:
|
||||
cd $(WXDIR)/src/x; $(MAKE) -f makefile.unx GUI=$(GUI)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(WXSOCKLIB): $(OBJECTS)
|
||||
rm -f $@
|
||||
ar $(AROPTIONS) libwxsock.a $(OBJECTS)
|
||||
$(RANLIB) libwxsock.a
|
||||
|
||||
$(OBJDIR)/wx_sock.$(OBJSUFF): wx_sock.$(SRCSUFF) wx_sock.h
|
||||
$(CC) -c $(CPPFLAGS) -o $@ wx_sock.$(SRCSUFF)
|
||||
|
||||
$(OBJDIR)/wx_addr.$(OBJSUFF): wx_addr.$(SRCSUFF) wx_addr.h
|
||||
$(CC) -c $(CPPFLAGS) -o $@ wx_addr.$(SRCSUFF)
|
||||
|
||||
$(OBJDIR)/test.$(OBJSUFF): test.$(SRCSUFF)
|
||||
$(CC) -c $(CPPFLAGS) -o $@ test.$(SRCSUFF)
|
||||
|
||||
$(TESTPROGRAM): $(OBJDIR)/test.$(OBJSUFF) $(WXLIB) $(WXSOCKLIB)
|
||||
$(CC) $(CPPFLAGS) $(LDFLAGS) -o test$(GUISUFFIX) $(OBJDIR)/test.$(OBJSUFF) $(XVIEW_LINK) $(LDLIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) test$(GUISUFFIX) $(WXSTRINGLIB) $(OBJDIR)/test.$(OBJSUFF) core
|
||||
|
58
samples/wxsocket/makefile.nt
Normal file
58
samples/wxsocket/makefile.nt
Normal file
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# File: makefile.nt
|
||||
# Author: Stefan Hammes (stefan.hammes@urz.uni-heidelberg.de) / Julian Smart / Petr Houser (1996)
|
||||
# Created: 1995
|
||||
# Updated:=09
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds wxSock library for Windows NT / Win95
|
||||
!include <..\..\..\src\ntwxwin.mak>
|
||||
|
||||
# Change WXDIR or WXWIN to wherever wxWindows is found
|
||||
#WXWIN = $(WX)
|
||||
WXDIR = $(WXWIN)
|
||||
WXINC = $(WXDIR)\include\msw
|
||||
|
||||
WXSOCKDIR = $(WXDIR)\contrib\wxsock
|
||||
WXSOCKINC = $(WXSOCKDIR)
|
||||
WXSOCKLIB = $(WXSOCKDIR)\lib\wxsock.lib $(WXSOCKDIR)\lib\zlib.lib
|
||||
INC=-I$(WXBASEINC) -I$(WXINC) -I$(WXSOCKINC)
|
||||
|
||||
WXLIB = $(WXDIR)\lib\wx.lib
|
||||
|
||||
LIBS=$(WXSOCKLIB) wsock32.lib $(LIBS)
|
||||
#LIBS=$(WXLIB) $(WXSTRINGLIB) oldnames libw llibcew llibce commdlg shell
|
||||
|
||||
all: client.exe server.exe
|
||||
|
||||
wx:
|
||||
cd $(WXDIR)\src\msw
|
||||
nmake -f makefile.nt
|
||||
cd $(ITSYDIR)
|
||||
|
||||
client.exe: $(WXDIR)\src\msw\dummy.obj $(WXLIB) $(WXSTRINGLIB) client.obj\
|
||||
client.res
|
||||
$(link) -out:client.exe $(LINKFLAGS) $(DUMMYOBJ) client.obj \
|
||||
client.res $(LIBS)
|
||||
|
||||
server.exe: $(WXDIR)\src\msw\dummy.obj $(WXLIB) $(WXSTRINGLIB) server.obj
|
||||
$(link) -out:server.exe $(LINKFLAGS) $(DUMMYOBJ) server.obj $(LIBS)
|
||||
|
||||
client.obj: client.$(SRCSUFF)
|
||||
$(cc) $(CPPFLAGS2) /c /Tp $*.$(SRCSUFF)
|
||||
|
||||
client.res: client.rc $(WXDIR)\include\msw\wx.rc
|
||||
$(rc) -r /i$(WXDIR)\include\msw /i$(WXDIR)\contrib\fafa -fo$@ client.rc
|
||||
|
||||
|
||||
server.obj: server.$(SRCSUFF)
|
||||
$(cc) $(CPPFLAGS2) /c /Tp $*.$(SRCSUFF)
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase *.exe
|
||||
-erase *.lib
|
||||
-erase *.res
|
||||
-erase *.sbr
|
||||
-erase *.pdb
|
BIN
samples/wxsocket/mondrian.ico
Normal file
BIN
samples/wxsocket/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
44
samples/wxsocket/mondrian.xpm
Normal file
44
samples/wxsocket/mondrian.xpm
Normal file
@@ -0,0 +1,44 @@
|
||||
/* XPM */
|
||||
static char *mondrian_xpm[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"32 32 6 1",
|
||||
" c Black",
|
||||
". c Blue",
|
||||
"X c #00bf00",
|
||||
"o c Red",
|
||||
"O c Yellow",
|
||||
"+ c Gray100",
|
||||
/* pixels */
|
||||
" ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" "
|
||||
};
|
189
samples/wxsocket/server.cpp
Normal file
189
samples/wxsocket/server.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* File: server.cpp
|
||||
* Purpose: wxSocket: server demo
|
||||
* Author: LAVAUX Guilhem (from minimal.cc)
|
||||
* Created: June 1997
|
||||
* Updated:
|
||||
* Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
* (C) 1997, LAVAUX Guilhem
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "wx/socket.h"
|
||||
|
||||
// Define a new application type
|
||||
class MyApp: public wxApp
|
||||
{ public:
|
||||
bool OnInit(void);
|
||||
};
|
||||
|
||||
class MyServer;
|
||||
|
||||
// Define a new frame type
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
DECLARE_EVENT_TABLE()
|
||||
public:
|
||||
MyServer *sock;
|
||||
int nb_clients;
|
||||
|
||||
MyFrame(wxFrame *frame);
|
||||
virtual ~MyFrame();
|
||||
void Menu_Exit(wxCommandEvent& evt);
|
||||
void ExecTest1(wxSocketBase *sock_o);
|
||||
void UpdateStatus(int incr);
|
||||
};
|
||||
|
||||
#define SKDEMO_QUIT 101
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(SKDEMO_QUIT, MyFrame::Menu_Exit)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
class MySock: public wxSocketBase {
|
||||
public:
|
||||
MyFrame *frame;
|
||||
|
||||
void OldOnNotify(wxRequestEvent flags);
|
||||
};
|
||||
|
||||
class MyServer: public wxSocketServer {
|
||||
public:
|
||||
MyFrame *frame;
|
||||
|
||||
MyServer(wxSockAddress& addr) : wxSocketServer(addr) { }
|
||||
void OldOnNotify(wxRequestEvent flags);
|
||||
};
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
// `Main program' equivalent, creating windows and returning main app frame
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
// Create the main frame window
|
||||
MyFrame *frame = new MyFrame(NULL);
|
||||
|
||||
// Give it an icon
|
||||
#ifdef wx_msw
|
||||
frame->SetIcon(new wxIcon("mondrian"));
|
||||
#endif
|
||||
#ifdef wx_x
|
||||
frame->SetIcon(new wxIcon("aiai.xbm"));
|
||||
#endif
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(SKDEMO_QUIT, "E&xit");
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
menu_bar->Append(file_menu, "File");
|
||||
frame->SetMenuBar(menu_bar);
|
||||
|
||||
// Make a panel with a message
|
||||
(void)new wxPanel(frame, 0, 0, 300, 100);
|
||||
|
||||
// Show the frame
|
||||
frame->Show(TRUE);
|
||||
|
||||
// Return the main frame window
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void MySock::OldOnNotify(wxRequestEvent flags)
|
||||
{
|
||||
extern wxList wxPendingDelete;
|
||||
|
||||
switch (flags) {
|
||||
case EVT_READ:
|
||||
unsigned char c;
|
||||
|
||||
ReadMsg((char *)&c, 1);
|
||||
if (c == 0xbe)
|
||||
frame->ExecTest1(this);
|
||||
|
||||
break;
|
||||
case EVT_LOST:
|
||||
frame->UpdateStatus(-1);
|
||||
wxPendingDelete.Append(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MyServer::OldOnNotify(wxRequestEvent WXUNUSED(flags))
|
||||
{
|
||||
MySock *sock2 = new MySock();
|
||||
|
||||
if (!AcceptWith(*sock2))
|
||||
return;
|
||||
|
||||
m_handler->Register(sock2);
|
||||
|
||||
sock2->SetFlags(NONE);
|
||||
sock2->frame = frame;
|
||||
sock2->SetNotify(REQ_READ | REQ_LOST);
|
||||
sock2->Notify(TRUE);
|
||||
frame->UpdateStatus(1);
|
||||
}
|
||||
|
||||
// My frame Constructor
|
||||
MyFrame::MyFrame(wxFrame *frame):
|
||||
wxFrame(frame, -1, "wxSocket sample (server)", wxDefaultPosition,
|
||||
wxSize(300, 200))
|
||||
{
|
||||
wxIPV4address addr;
|
||||
addr.Service(3000);
|
||||
|
||||
// Init all
|
||||
wxSocketHandler::Master();
|
||||
|
||||
sock = new MyServer(addr);
|
||||
wxSocketHandler::Master().Register(sock);
|
||||
sock->frame = this;
|
||||
sock->SetNotify(wxSocketBase::REQ_ACCEPT);
|
||||
sock->Notify(TRUE);
|
||||
nb_clients = 0;
|
||||
|
||||
CreateStatusBar(1);
|
||||
UpdateStatus(0);
|
||||
}
|
||||
|
||||
MyFrame::~MyFrame()
|
||||
{
|
||||
delete sock;
|
||||
}
|
||||
|
||||
// Intercept menu commands
|
||||
void MyFrame::Menu_Exit(wxCommandEvent& event)
|
||||
{
|
||||
Close(TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::ExecTest1(wxSocketBase *sock_o)
|
||||
{
|
||||
char *buf = new char[50];
|
||||
size_t l;
|
||||
|
||||
l = sock_o->Read(buf, 50).LastCount();
|
||||
sock_o->Write(buf, l);
|
||||
}
|
||||
|
||||
void MyFrame::UpdateStatus(int incr)
|
||||
{
|
||||
char s[30];
|
||||
nb_clients += incr;
|
||||
sprintf(s, "%d clients connected", nb_clients);
|
||||
SetStatusText(s);
|
||||
}
|
8
samples/wxsocket/server.def
Normal file
8
samples/wxsocket/server.def
Normal file
@@ -0,0 +1,8 @@
|
||||
NAME Server
|
||||
DESCRIPTION 'Server'
|
||||
EXETYPE WINDOWS
|
||||
STUB 'WINSTUB.EXE'
|
||||
CODE PRELOAD MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE MULTIPLE
|
||||
HEAPSIZE 4096
|
||||
STACKSIZE 8192
|
4
samples/wxsocket/server.rc
Normal file
4
samples/wxsocket/server.rc
Normal file
@@ -0,0 +1,4 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
conn_icn ICON "connect.ico"
|
||||
#include "wx.rc"
|
||||
|
Reference in New Issue
Block a user