fmII
Tue, May 13th home | browse | articles | contact | chat | submit | faq | newsletter | about | stats | scoop 17:36 PDT
in
Section
login «
register «
recover password «
[Project] add release | add branch | add screenshot | broken links | change owner | email subscribers | update project | update branch (urls) [Project]

 C++ Sockets - Default branch
Section: Unix

 

Added: Mon, Feb 16th 2004 02:30 PDT (4 years, 2 months ago) Updated: Tue, Apr 15th 2008 07:49 PDT (28 days ago)


About:
C++ Sockets is a cross-platform C++ wrapper for BSD-style sockets. It implements the TCP, UDP, ICMP, and SCTP transport layer protocols. Implemented application layer protocols are HTTP/HTTPS (using OpenSSL), SMTP (server), and Ajp/1.3 (server). Features include transparent SOCKS4 client support and asynchronous DNS. Included in the library are a number of HTTP client functions such as GET/PUT/POST, and also Web server framework components.

Author:
Grymse [contact developer]

Rating:
8.76/10.00 (6 votes)

Homepage:
http://www.alhem.net/Sockets/index.html
Tar/GZ:
http://www.alhem.net/Sockets/Sockets-2.2.9a.tar.gz
Zip:
http://www.alhem.net/Sockets/Sockets-2.2.9a.zip
Changelog:
http://www.alhem.net/Sockets/Changelog
RPM package:
http://dries.studentenweb.org/rpm/packages/csockets/info.html
BSD Ports URL:
http://www.freshports.org/net/Sockets/
Purchase:
http://www.alhem.net/Sockets/license.html

Trove categories: [change]
[Intended Audience]  Developers
[License]  OSI Approved :: GNU General Public License (GPL)
[Operating System]  MacOS X, Microsoft, POSIX :: Linux, POSIX :: SunOS/Solaris
[Programming Language]  C++
[Topic]  Communications, System :: Networking

Dependencies: [change]
No dependencies filed

 
Project admins: [change]
» Grymse (Owner)

» Rating: 8.76/10.00 (Rank N/A)
» Vitality: 0.83% (Rank 345)
» Popularity: 5.93% (Rank 527)

project statsdownload stats
(click to enlarge graphs)
   Record hits: 84,080
   URL hits: 34,102
   Subscribers: 111

Projects depending on this project:
Robotworld
The Minder
Distributed Chat
A Small MUD
Tjukebox
(Note: 11 projects depend on this one. The ones displayed are picked by a randomizer.)


Other projects from the same categories:
MultiMail
Format XML
libjhttpd
gh-tool
QuickServer

Users who subscribed to this project also subscribed to:
Xdialog
CrossVC
Checkbot
sitecopy
deborphan


Add comment · Rate this project · Subscribe to new releases · Ignore this project · Email this project to a friend · Project record in XML

 Branches

Branch Version Last release License URLs
Default 2.2.9a 15-Apr-2008 GNU General Public License (GPL) Homepage Tar/GZ Changelog

 Comments

[»] Compilation error
by Daniel Feiglin - May 30th 2007 10:45:41

...
g++ -Wall -g -MD -D_VERSION='"2.1.6"' -O2 -DLINUX -c -o Sockets-config.o Sockets-config.cpp
g++ -o Sockets-config Sockets-config.o
/usr/lib/gcc/i586-suse-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0xc): undefined reference to `__libc_csu_fini'
/usr/lib/gcc/i586-suse-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0x11): undefined reference to `__libc_csu_init'
collect2: ld returned 1 exit status
make: *** [Sockets-config] Error 1
danny:~/installs/Sockets-2.1.6 #

This also happened with 2.1.5. Version 2.1.4 was OK

[reply] [top]


[»] Problems in compiling test program in DevC++
by JD - Mar 4th 2007 13:24:48

Hi,

I am a newbie in C++ programming. I downloaded the zip of source code and tried to compile the test.cpp in DevC++ environment.I have installed OpenSSL but still I am getting following errors. Please help.

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Jaideep Padhye\Desktop\Sockets-2.1\Sockets-2.1\DevCpp\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Jaideep Padhye\Desktop\Sockets-2.1\Sockets-2.1\DevCpp\Makefile.win" all
g++.exe -c ../sockets_test.cpp -o bin/sockets_test.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I".." -DHAVE_OPENSSL

g++.exe bin/sockets_test.o -o "..\..\bin\Test.exe" -L"C:/Dev-Cpp/lib" -L"C:/OpenSSL/lib/MinGW" ../../lib/Sockets.a ../../../../DevCpp/lib/libwsock32.a ../../../../OpenSSL/lib/MinGW/ssleay32.a ../../../../OpenSSL/lib/MinGW/libeay32.a

g++.exe: ../../../../DevCpp/lib/libwsock32.a: No such file or directory
g++.exe: ../../../../OpenSSL/lib/MinGW/ssleay32.a: No such file or directory
g++.exe: ../../../../OpenSSL/lib/MinGW/libeay32.a: No such file or directory

make.exe: *** [../../bin/Test.exe] Error 1

Execution terminated

[reply] [top]


[»] make for Mac OS X
by aula1 - Oct 27th 2006 00:08:18

Hi, I'am using Mac OS X 10.2.8 I've recently installed the Operative System.
When I try make Sockets-2.1, I get the following error:

g++ -Wall -g -I. -MD -D_VERSION='"2.1"' -O2 -DMACOSX -DSOCKETS_NAMESPACE=sockets -D_DEBUG -c -o Socket.o Socket.cpp
In file included from Socket.cpp:45:
SocketAddress.h:29: error: parse error before `(' token
SocketAddress.h:29: warning: ISO C++ forbids declaration of `<invalid operator>
' with no type
SocketAddress.h:29: error: `<invalid operator>' declared as a `virtual' field
Socket.cpp: In member function `virtual void sockets::Socket::OnException()':
Socket.cpp:171: error: `socklen_t' undeclared (first use this function)
Socket.cpp:171: error: (Each undeclared identifier is reported only once for
each function it appears in.)
Socket.cpp:171: error: parse error before `=' token
Socket.cpp:175: error: `errlen' undeclared (first use this function)
Socket.cpp: In member function `virtual bool sockets::Socket::CheckConnect()':
Socket.cpp:195: error: parse error before `=' token
make: *** [Socket.o] Error 1

The project compiles in Windows XP without problems.
What I'm doing wrong? I'm newbye in Mac architecture.
I'll appreciate your help.
Salutations.

[reply] [top]


[»] make docs: broken in 1.7.1?
by Leo Dearden - Jan 21st 2005 08:45:41

Source archive downloaded 2005-01-20 from http://www.alhem.net/Sockets/index.html

$tar -xvzf Sockets-1.7.1.tar.gz
$cd Sockets-1.7.1
$make docs
rm -f *.o *~ slask *.d *.a
rm -f Mutex.*
rm -f MinderSocket_T.h
rm -f uuid.h
rm -f Stdin.*
./mkdot.sh
make: ./mkdot.sh: Command not found
make: *** [docs] Error 127
$ls *.sh
ls: *.sh: No such file or directory

The problem appears to be that mkdot.sh is missing from the archive. The action to add it to the action to add it to the archive seems to be missisg from the tar target too.

--
Leo

[reply] [top]


    [»] Re: make docs: broken in 1.7.1?
    by Grymse - Jan 22nd 2005 23:41:56


    > Source archive downloaded 2005-01-20

    > from

    > http://www.alhem.net/Sockets/index.html

    >

    >

    > $tar -xvzf Sockets-1.7.1.tar.gz

    > $cd Sockets-1.7.1

    > $make docs

    > rm -f *.o *~ slask *.d *.a

    > rm -f Mutex.*

    > rm -f MinderSocket_T.h

    > rm -f uuid.h

    > rm -f Stdin.*

    > ./mkdot.sh

    > make: ./mkdot.sh: Command not found

    > make: *** [docs] Error 127

    > $ls *.sh

    > ls: *.sh: No such file or directory

    >

    > The problem appears to be that mkdot.sh

    > is missing from the archive. The action

    > to add it to the action to add it to the

    > archive seems to be missisg from the tar

    > target too.


    Hi
    It's a small script that uses Doxygen (www.doxygen.org) and my project "dp" (www.alhem.net/project/dp) to generate the documentation shown on the sockets library homepage. I'll include it in the next release.
    Best regards
    /ah

    [reply] [top]


[»] how to know the port number ?
by iw3gtf - Oct 30th 2004 08:21:04

Hallo,
I have a problem I cannot solve: I want to have more listening sockets on the same local ip address but on different ports, say on port 1024 and 1025. I have a SocketHandler instance and 2 ListenSocket<MyHttpSocket> but when an incoming connection is being accepted and a new instance of my MyHttpSocket is created I'm no more able to know on which port the connection request arrived, 1024 or 1025. Moreover I cannot start 2 server processes, one on each port, because of other reasons that'll take too long to explain...
Is there a solution to this case?

Thank you for your help.

--
Giorgio, iw3gtf@libero.it

[reply] [top]


    [»] Re: how to know the port number ?
    by Grymse - Oct 31st 2004 00:33:39


    > Hallo,

    > I have a problem I cannot solve: I want

    > to have more listening sockets on the

    > same local ip address but on different

    > ports, say on port 1024 and 1025. I have

    > a SocketHandler instance and 2

    > ListenSocket<MyHttpSocket> but

    > when an incoming connection is being

    > accepted and a new instance of my

    > MyHttpSocket is created I'm no more able

    > to know on which port the connection

    > request arrived, 1024 or 1025. Moreover

    > I cannot start 2 server processes, one

    > on each port, because of other reasons

    > that'll take too long to explain...

    > Is there a solution to this case?

    >

    > Thank you for your help.

    Hi,
    My quick solution is to add a GetParent() method in Socket, that will return the pointer to the ListenSocket that created it. This will be in the next version.
    In your socket class, you'd do something like this:

    switch ( GetParent()->GetPort() )
    {
    case 1024: // "server 1"
    break;
    case 1025: // "server 2"
    break;
    default: // wtf
    }

    Also, I'm sure there is a way to get the local port of the established connection, but didn't find it after a quick man browsing. If you just could get the port number directly from the connected socket...

    Oh well, I know this doesn't help much until the next release, but just that you know that there is a solution coming.

    [reply] [top]


      [»] Re: how to know the port number ?
      by iw3gtf - Nov 2nd 2004 00:55:19

      % Hi,

      > My quick solution is to add a

      > GetParent() method in Socket, that will

      > return the pointer to the ListenSocket

      > that created it. This will be in the

      > next version.

      > In your socket class, you'd do something

      > like this:

      >

      > switch ( GetParent()->GetPort() )

      > {

      > case 1024: // "server 1"

      > break;

      > case 1025: // "server 2"

      > break;

      > default: // wtf

      > }

      >

      > Also, I'm sure there is a way to get the

      > local port of the established

      > connection, but didn't find it after a

      > quick man browsing. If you just could

      > get the port number directly from the

      > connected socket...

      >

      > Oh well, I know this doesn't help much

      > until the next release, but just that

      > you know that there is a solution

      > coming.

      >

      >

      Hi,
      thanks for the quick new release. This evening I will try to update my server.

      Bye.

      --
      Giorgio, iw3gtf@libero.it

      [reply] [top]


[»] disconnect and races
by vertigo7 - Oct 24th 2004 05:08:28

Hello I have clientA and clientB. They talk thru Socket class. The problem is durring disconnection.
In clientB:
if (handler!=NULL && socket!=NULL && handler.Valid(socket) && socket.CheckConnect()){
//here possibly clientA disconnects and socket is closed.
//send some data thru socket
}

i receive in clientB segmentation fault, gdb says: "Program received SIGSEGV.... in Socket::Handler (this=0x0) at Socket.cpp:553
How can i solve this problem ?
Thanx

[reply] [top]


    [»] Re: disconnect and races
    by Grymse - Oct 26th 2004 04:58:19


    > Hello

    > I have clientA and clientB. They talk

    > thru Socket class. The problem is

    > durring disconnection.

    >

    > In clientB:

    > if (handler!=NULL && socket!=NULL &&

    > handler.Valid(socket) &&

    > socket.CheckConnect()){

    > //here possibly clientA disconnects and

    >

    > socket is closed.

    > //send some data thru socket

    > }

    >

    >

    > i receive in clientB segmentation fault,

    > gdb says:

    > "Program received SIGSEGV.... in

    > Socket::Handler (this=0x0) at

    > Socket.cpp:553

    >

    > How can i solve this problem ?

    >

    > Thanx

    >


    Hiya,
    if you have set "SetDeleteByHandler" to true, the SocketHandler class will delete the Socket class when the connection is broken - or something else fails.
    If you use the Socket class pointer outside the SocketHandler, you could end up with an illegal pointer eventually.
    If you post more specific code I might be able to see the problem.
    The error you got was a call to Socket::Handler(), when to Socket class pointer was NULL.

    [reply] [top]


      [»] Re: disconnect and races
      by vertigo7 - Oct 27th 2004 07:01:48

      Hello
      Yet again it was my fatal error.
      Now everything works fine :))

      [reply] [top]


[»] Compilation Failure Under SuSE 9.1
by Daniel Feiglin - Sep 28th 2004 05:33:44

Scotch my last remark. I just remembered that we had the same thing under 1.5.2, and the solution is somewhere below.

[reply] [top]


[»] Compilation Failure under SuSE 91.
by Daniel Feiglin - Sep 28th 2004 05:28:00

1. Define LINUX in Makefile
2. Openssl installed and defined

Problem: Compile fails with missing uuid/uuid.h

There is a file uuid.h in /usr/src/linux/fs/xfs/support but it seems irrelevant. Anyway, just for the fun of it, moving it to the compile directory and changing the <uuid/uuid.h> to "uuid.h" in the Makefile doesn't help very much. Here are some of the comiler error messages:

Uid.cpp: In constructor `Uid::Uid()':
Uid.cpp:55: error: `uuid_generate' undeclared (first use this function)
Uid.cpp:55: error: (Each undeclared identifier is reported only once for each
function it appears in.)
Uid.cpp:56: error: cannot convert `uuid_t' to `const void*' for argument `2' to
`void* memcpy(void*, const void*, unsigned int)'

[reply] [top]


    [»] Re: Compilation Failure under SuSE 91.
    by jmalicki - Oct 30th 2004 04:07:55

    Install the e2fsprogs-devel (or whatever it is that SUSE calls them) package.

    [reply] [top]


[»] reading/writing binary data
by vertigo7 - Sep 13th 2004 08:57:42

Hello
Till now i used TCPSocket::OnLine() to read data. But i have to change my protocol to binary. And i am concerned about data integrity. For example: what will happen if on one computer i will call:
Send("data1_some_binary...");
Send("data2_some_binary...");
Should i use OnRawData() to read it ? (i assume that yes). But do i have guaranty that on computer which receives OnRawData() will be called two times with exactly same data ? Even if "data1_some_binary" is 1MB long ? I assume that it's all hapening on one TCP connection. If i do not have any guaranty how can i check if i received whole packet ?
Thanx
Michal

[reply] [top]


    [»] Re: reading/writing binary data
    by Grymse - Sep 14th 2004 10:23:27


    > Hello

    > Till now i used TCPSocket::OnLine() to

    > read data. But i have to change my

    > protocol to binary. And i am concerned

    > about data integrity. For example: what

    > will happen if on one computer i will

    > call:

    > Send("data1_some_binary...");

    > Send("data2_some_binary...");

    > Should i use OnRawData() to read it ? (i

    > assume that yes). But do i have guaranty

    > that on computer which receives

    > OnRawData() will be called two times

    > with exactly same data ? Even if

    > "data1_some_binary" is 1MB long ?

    > I assume that it's all hapening on one

    > TCP connection. If i do not have any

    > guaranty how can i check if i received

    > whole packet ?

    >

    > Thanx

    > Michal

    >

    When doing binary, OnRawData() can be called with any number of bytes - depending on the network transfer mood of the moment. So your binary protocol has to have a way to determine the size of each message.
    One way is to make the first two bytes of every message indicate the length of the whole message. Tcp takes care of delivering your stream intact so you don't have to worry about checksums unless you're really paranoid that is.

    [reply] [top]


      [»] sending binary data
      by vertigo7 - Sep 15th 2004 08:16:26

      Hello
      Does std::string allow to keep data as unsigned char ? Does Send(std::string) send data from string converting it to char* ? For example: if i have:
      std::string s="";
      s[0]=100;
      s[1]=200;
      s[2]=0;
      s[3]=60;

      will Send() send all 4 codes ? (or just 2?), and if code==200 will be converted to char (or not) ?
      Thanx
      Michal

      [reply] [top]


        [»] Re: sending binary data
        by Grymse - Sep 15th 2004 11:05:58


        > Hello

        > Does std::string allow to keep data as

        > unsigned char ? Does Send(std::string)

        > send data from string converting it to

        > char* ? For example: if i have:

        > std::string s="";

        > s[0]=100;

        > s[1]=200;

        > s[2]=0;

        > s[3]=60;

        >

        >

        > will Send() send all 4 codes ? (or just

        > 2?), and if code==200 will be converted

        > to char (or not) ?

        >

        >

        > Thanx

        >

        > Michal

        >


        Hiya Michal,
        Use an unsigned char[] when working with binary, and SendBuf(buffer, length) when sending data.
        That way you are always sure.

        [reply] [top]


[»] problem with SetCloseAndDelete()
by vertigo7 - Sep 6th 2004 10:34:48

Hello
I have ServerHandler where is ListenSocket with type ServerSocket and ClientHandler where are ClientSockets. When other machines connects to my machine new ServerSockets are created and they are added to ServerHandler ? I'm asking because i have strange problem with SetCloseAndDelete() on such ServerSocket. Connection is closed, but after that i can not open any new connection using ClientSocket.
Other problem with ServerSocket: when i receive new connection in OnConnect() i set flag connected, and call node->Receive(this) (node is object who owns all this) to tell that i received connection. Receive() save pointer to ServerSocket class, so later i could use node->Send() using this connection. Problem is when i later try to use that object flag is not set. I have exactly same code for ClientSocket and there everything works fine. I propably miss something but can't find what. What could it be ?
Thanx Michal

[reply] [top]


    [»] Re: problem with SetCloseAndDelete()
    by Grymse - Sep 6th 2004 23:34:11


    > Hello

    > I have ServerHandler where is

    > ListenSocket with type ServerSocket and

    > ClientHandler where are ClientSockets.

    > When other machines connects to my

    > machine new ServerSockets are created

    > and they are added to ServerHandler ?

    > I'm asking because i have strange

    > problem with SetCloseAndDelete() on such

    > ServerSocket. Connection is closed, but

    > after that i can not open any new

    > connection using ClientSocket.

    >
    Do you reuse the socket class when you open a new connection, or do you create a new socket class for each new connection?
    I have never tried reusing a socket class after a connection has closed. Always create a new socket class for each connection just to be safe.


    > Other problem with ServerSocket: when i

    > receive new connection in OnConnect() i

    > set flag connected, and call

    > node->Receive(this) (node is object who

    > owns all this) to tell that i received

    > connection. Receive() save pointer to

    > ServerSocket class, so later i could use

    > node->Send() using this connection.

    > Problem is when i later try to use that

    > object flag is not set. I have exactly

    > same code for ClientSocket and there

    > everything works fine. I propably miss

    > something but can't find what. What

    > could it be ?
    When working with socket class pointers outside the socket handler, remember to always check ClientHandler.Valid(your_socket_pointer) - if the socket handler class has deleted your object you end up with an invalid pointer.


    >

    > Thanx

    > Michal

    [reply] [top]


      [»] Re: problem with SetCloseAndDelete()
      by vertigo7 - Sep 7th 2004 02:28:24

      Thanx, again found fatal error, everything works fine now :))

      [reply] [top]


[»] checking opened & succesful connection
by vertigo7 - Sep 6th 2004 03:07:23

Hello
How can i check if ClientSocket has succesfully opened connection & send data ? I tried to read value returned by open() but was always the same.
I save pointers to ClientSocket object in special list, and use it when i want to send something to someone. The problem is when other side disconnect. Pointers still points to some address but there seems to not be ClientSocket object. How can i check if it still exists ?
Thanx Michal

[reply] [top]


    [»] Re: checking opened & succesful connection
    by Grymse - Sep 6th 2004 04:27:52


    > Hello

    > How can i check if ClientSocket has

    > succesfully opened connection & send

    > data ? I tried to read value returned by

    > open() but was always the same.

    >
    Use the OnConnect() method to set a "connected" flag on your socket class.


    > I save pointers to ClientSocket object

    > in special list, and use it when i want

    > to send something to someone. The

    > problem is when other side disconnect.

    > Pointers still points to some address

    > but there seems to not be ClientSocket

    > object. How can i check if it still

    > exists ?
    Use the sockethandler method Valid() to check that a socket pointer is still valid.


    >

    >

    > Thanx

    > Michal

    [reply] [top]


[»] httpget + client == seg.fault ?
by vertigo7 - Sep 5th 2004 01:14:31

Hello
in one program i used HttpGet() from httpget example, and client from client/server example. When i try to create/add/select ClientSocket then call HttpGet() and again create/add/select ClientSocket i receive seg.fault. gdb says:
free(): invalid pointer 0xfef8e920!
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -150142848 (LWP 6387)]
std::_List_base::__clear (
this=0xfef8e994) at list.tcc:76
76 __cur = static_cast(__cur->_M_next);
Current language: auto; currently c++

interesting is that i can use many times HttpGet(), and after it many times open/add/select ClientSocket and after it many times HttpGet() and it works fine.
Such error appears only when i used:
Client(1 or more times),HttpGet(1 or more times), Client.
Thera are some problems with free(), when i will disable function clientsocket.SetDeleteByHandler() after creating clientsocket there is no segmentation fault, but in that moment where was seg.fault client does not send any packet (but there are no errors).
What's wrong ?
Thanx Michal

[reply] [top]


    [»] Re: httpget + client == seg.fault ?
    by vertigo7 - Sep 6th 2004 00:34:46

    it's working now, it was my mistake :))

    [reply] [top]


      [»] Re: httpget + client == seg.fault ?
      by PizzaHut - Oct 16th 2004 01:38:03


      > it's working now, it was my mistake :))

      Hi vertigo7
      How did you make it work now?Could you tell me a good way to trace such an error?Now I meet the similar error.When I use GDB to debug my program,it tells me "free() invalid pointer *****".But I haven't an effective way to solve it.

      [reply] [top]


[»] Socket.Select()
by vertigo7 - Sep 5th 2004 00:07:25

Hello In which moment is data send thru ClientSocket ? When i have code:
void Node::ConnectTo(char* ip, int port, char *data){
NodeClientSocket c(Clienth,data,this);
c.Open(ip,port);
Clienth.Add(&c);
Clienth.Select(1,0);
}
this function will finish when all data will be send, or imediately ? It after sending all data is it good idea to launch this function from new thread ?
And other problem: i created thread in which i wanted to check if there is something to send, and send it if nececary send it:
void* Node::StartClientsLoop(void* n){
Node *node=(Node*)n;
node->Clienth.Select(1,0);
while(1){
usleep(200000);
if (node->Clienth.GetCount())
node->Clienth.Select(1,0);
}
return NULL;
}
but it seg. fault on Select(). Is such thead nececary ?
Thanx Michal

[reply] [top]


    [»] Re: Socket.Select()
    by Grymse - Sep 6th 2004 02:11:31


    > Hello

    > In which moment is data send thru

    > ClientSocket ?

    > When i have code:

    > void Node::ConnectTo(char* ip, int port,

    > char *data){

    > NodeClientSocket

    > c(Clienth,data,this);

    > c.Open(ip,port);

    > Clienth.Add(&c);

    > Clienth.Select(1,0);

    > }

    > this function will finish when all data

    > will be send,

    > or imediately ?

    > It after sending all data is it good

    > idea to launch this function from new

    > thread ?

    >
    Your function will return immediately, and leave a temporary socket object in your socket handler. When you add a socket class to the handler you must make sure the object stays allocated until either you delete it or the socket handler deletes it. In your function above, your socket object will disappear when your function returns with probably a seg.fault as a result.


    > And other problem: i created thread in

    > which i wanted to check if there is

    > something to send,

    > and send it if nececary send it:

    > void* Node::StartClientsLoop(void* n){

    > Node *node=(Node*)n;

    > node->Clienth.Select(1,0);

    > while(1){

    > usleep(200000);

    > if (node->Clienth.GetCount())

    > node->Clienth.Select(1,0);

    > }

    > return NULL;

    > }

    > but it seg. fault on Select(). Is such

    > thead nececary ?

    >

    > Thanx

    > Michal

    >

    Data is sent when you call Send() or SendBuf() on a socket class. If there is too much data to send at once, you have to repeatedly call the sockethandler method Select until all data is sent.
    Either way, you should continually call Select because that method handles everything - reading, writing, accepting new connections, cleaning up old connections etc etc.

    [reply] [top]


[»] using opened ClientSockets
by vertigo7 - Sep 4th 2004 23:56:30

Hello
Thanx for previous answers :)
I have another question:
When i've opened some ClientSockets which are held by ClientHandler. I want to reuse them, so i could send some data thru socket which is already connected with specified IP. How can i do that ?
And one more question:
When i open socket, and do not send nothing thru it after a while (about minute) it's being closed. (i observed netstat -te, and in first minute it had state TIME_WAIT and after about minute that connection disappeared). Is that operating system intervention ? (i did not use SetCloseAndDelete() ). If yes, is it resonable for me to implement mechanism which will send some random data frequently to keep alive that connection ?
Thanx Michal

[reply] [top]


    [»] Re: using opened ClientSockets
    by Grymse - Sep 6th 2004 01:58:31

    Yes, to be safe you should make your own keep-alive function. Make some kind of traffic once in a while to keep the connection open. See the KeepAlive() method in the MinderHandler class - in one distributed solution I call that method once every minute to keep the connection open.

    [reply] [top]


[»] passing pointer to NodeServerSocket
by vertigo7 - Sep 4th 2004 02:39:03

Hello
I write p2p client, and i used client/server example.
I have Node class where i start two threads: one reads data for ServerHandler (where is ServerSocket and other for ClientHandler(where are ClientsSockets). I need to create pointer to Node in SocketServer because i want to call Node->Read() in SocketServer->OnLine() to notify Node class that some data was read by ServerSocket.
The problem is that listener is created:
ListenSocket<ServerSocket> l(h);
and ServerSocket needs to have constructor:
ServerSocket::ServerSocket(SocketHandler& h)

is there any way i could pass pointer to Node object into ServerSocket class so it could notify Node object when some data arrives ?

Thanx
Michal

[reply] [top]


    [»] Re: passing pointer to NodeServerSocket
    by vertigo7 - Sep 4th 2004 05:56:54

    ok, i've made new class very similar to ListenSocket.h, and it's working fine :)
    I have another question:
    i do not want to close connections for TCPSocket until i receive special string. Until that i would like to keep that connection always alive. How can i implement it ?
    Thanx Michal

    [reply] [top]


      [»] Re: passing pointer to NodeServerSocket
      by vertigo7 - Sep 4th 2004 06:08:08

      i'm asking because i have problem: after sending thru ClientSocket some data, arter few second i receive core dump, seg. fault. But the packet arrives immediately and correctly, only client hangs after some time. I did not used SetCloseAndDelete() because i want to have connection kept alive....

      [reply] [top]


      [»] Re: passing pointer to NodeServerSocket
      by Grymse - Sep 4th 2004 09:12:44

      Hi
      Connections when using TcpSocket should stay open until an error occurs or until you use SetCloseAndDelete() to manually close them. If you have problems, use the StdoutLog class as error logging (see tutorial on error logging www.libsockets.net/tutorial/).
      Greetings
      /ah

      [reply] [top]


    [»] Re: passing pointer to NodeServerSocket
    by Grymse - Sep 4th 2004 09:08:00

    Hi Michal, I would suggest that your Handler's keeps a reference to your Node class, so that later on any socket can get the Node reference from it's SocketHandler. Something like this:
    class ServerHandler
    {
    ServerHandler(const Node& n) : m_node(n) { ... your stuff ... }

    ServerHandler::GetNode() { return m_node; }
    Node& m_node;
    }

    And in ServerSocket:
    ServerSocket::OnLine(const std::string& line)
    {
    static_cast<ServerHandler&>(Handler()).GetNode().Read();
    }

    Always try to use the SocketHandler class as your passthrough for things like this! Greetings /ah

    [reply] [top]


[»] Another example added
by Grymse - Feb 29th 2004 23:55:19

I've added code & docs for a very small tcp/ip proxy, using this library.

[reply] [top]


    [»] Make fails
    by Daniel Feiglin - Jul 13th 2004 06:12:48

    Here is the bit that fails: danny@danny:~/pub/installs/Sockets-1.5.3> make all g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o SSLSocket.o SSLSocket.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o HttpsGetSocket.o HttpsGetSocket.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o CTcpSocket.o CTcpSocket.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o HTTPSocket.o HTTPSocket.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o HttpsSocket.o HttpsSocket.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o Thread.o Thread.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o SocketThread.o SocketThread.cpp g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o StdoutLog.o StdoutLog.cpp ar cru libSockets.a CircularBuffer.o Socket.o SocketHandler.o TcpSocket.o UdpSocket.o Parse.o Base64.o NullCrypt.o HttpGetSocket.o SSLSocket.o HttpsGetSocket.o CTcpSocket.o HTTPSocket.o HttpsSocket.o Thread.o SocketThread.o StdoutLog.o ranlib libSockets.a g++ -Wall -g -O2 -I/usr/devel/include -I. -MD -D_VERSION='"1.5.3"' -DLINUX -c -o Uid.o Uid.cpp Uid.cpp:30:23: uuid/uuid.h: No such file or directory Uid.cpp: In constructor `Uid::Uid()': Uid.cpp:53: error: `uuid_t' undeclared (first use this function) Uid.cpp:53: error: (Each undeclared identifier is reported only once for each function it appears in.) Uid.cpp:53: error: parse error before `;' token Uid.cpp:54: error: `uid' undeclared (first use this function) Uid.cpp:54: error: `uuid_generate' undeclared (first use this function) I have nothing that looks like uuid.h anywhere else on my system. Is it a missing dependency? Thanks.

    [reply] [top]


      [»] Re: Make fails
      by Grymse - Jul 13th 2004 09:02:50

      Hi Danny "libuuid" is a small utility library that is part of the e2fsprogs for Linux. If you are using Linux then look for e2fsprogs. If you are using Mac OS X you can find uuid.h here: http://www.die.net/doc/linux/include/uuid/uuid.h

      [reply] [top]




© Copyright 2008 SourceForge, Inc., All Rights Reserved.
About freshmeat.net •  Privacy Statement •  Terms of Use •  Trademark Guidelines •  Advertise •  Contact Us • 
ThinkGeek •  Slashdot  •  ITMJ •  Linux.com •  NewsForge  •  SourceForge.net  •  Surveys •  Jobs •  PriceGrabber