Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 28, 2004 Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Attachments: | Attached my code. I tried to make it work for linux but was unable to
test it, I don't know much about linux. I get this error when running
dmd on debian:
./dmd: error while loading shared libraries: libstdc++.so.5: cannot open
shared object file: No such file or directory
I tried to install libstdc++ libs but the error remains.
I'd appreciate it if someone could help by getting the code to work for linux or helping me fix my problem :)
--
Christopher E. Miller
www.dprogramming.com
irc.dprogramming.com #D
|
February 28, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix Attachments: | Vathix wrote: > Attached my code. I tried to make it work for linux but was unable to > test it, I don't know much about linux. I get this error when running > dmd on debian: > ./dmd: error while loading shared libraries: libstdc++.so.5: cannot > open shared object file: No such file or directory > I tried to install libstdc++ libs but the error remains. From my own experience, that means you have to update a lot of things, not only that one, and with very recent versions. > > I'd appreciate it if someone could help by getting the code to work for linux or helping me fix my problem :) > > > -- > Christopher E. Miller > www.dprogramming.com > irc.dprogramming.com #D I've attached a slightly modified socket.d. From what I can remember: - version(linux) instead of Linux - declared fd_set for BsdSockets - blocking in Socket class was only defined for Windows, although being used in both versions. Commented out the line - errno declared as extern(C) I think that's it. ----------------------- Carlos Santander Bernal8 |
February 28, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Carlos Santander B. wrote:
> Vathix wrote:
>> Attached my code. I tried to make it work for linux but was unable
>> to test it, I don't know much about linux. I get this error when
>> running dmd on debian:
>> ./dmd: error while loading shared libraries: libstdc++.so.5: cannot
>> open shared object file: No such file or directory
>> I tried to install libstdc++ libs but the error remains.
>
> From my own experience, that means you have to update a lot of things, not only that one, and with very recent versions.
>
>>
>> I'd appreciate it if someone could help by getting the code to work for linux or helping me fix my problem :)
>>
>>
>> --
>> Christopher E. Miller
>> www.dprogramming.com
>> irc.dprogramming.com #D
>
>
> I've attached a slightly modified socket.d. From what I can remember:
> - version(linux) instead of Linux
> - declared fd_set for BsdSockets
> - blocking in Socket class was only defined for Windows, although
> being used in both versions. Commented out the line
> - errno declared as extern(C)
>
> I think that's it.
>
> -----------------------
> Carlos Santander Bernal
I tested it on RedHat 9, and it compiled without a problem, but when testing it, I got "Socket select error". Any ideas?
-----------------------
Carlos Santander Bernal
|
February 28, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | > I tested it on RedHat 9, and it compiled without a problem, but when testing > it, I got "Socket select error". Any ideas? > > ----------------------- > Carlos Santander Bernal > Yes, fd_set is handled differently for linux, I'm working on it now. I got DMD to work on linux. Thanks for your help. -- Christopher E. Miller |
February 28, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Carlos Santander B. wrote: > Carlos Santander B. wrote: > >>Vathix wrote: >> >>>Attached my code. I tried to make it work for linux but was unable >>>to test it, I don't know much about linux. I get this error when >>>running dmd on debian: >>>./dmd: error while loading shared libraries: libstdc++.so.5: cannot >>>open shared object file: No such file or directory >>>I tried to install libstdc++ libs but the error remains. >> >>From my own experience, that means you have to update a lot of >>things, not only that one, and with very recent versions. >> >> >>>I'd appreciate it if someone could help by getting the code to work >>>for linux or helping me fix my problem :) >>> >>> >>>-- >>>Christopher E. Miller >>>www.dprogramming.com >>>irc.dprogramming.com #D >> >> >>I've attached a slightly modified socket.d. From what I can remember: >>- version(linux) instead of Linux >>- declared fd_set for BsdSockets >>- blocking in Socket class was only defined for Windows, although >>being used in both versions. Commented out the line >>- errno declared as extern(C) >> >>I think that's it. >> >>----------------------- >>Carlos Santander Bernal > > > I tested it on RedHat 9, and it compiled without a problem, but when testing > it, I got "Socket select error". Any ideas? > > ----------------------- > Carlos Santander Bernal > > I have tested it on Slackware and run fine with some changes.... At first, the "Socket select error" is right, because you haven't a http server listening at 127.0.0.1 port 80 The second is that Socket.select is not right implemented for linux (at first reading of socked.d) comment it on and will run ok. try this modified version for sockettest.d (watch the commented lines, real IP number and s.send string with a true http site.... ;-) : import socket; // dmd sockettest socket ws2_32.lib int main() { /+ //regular blocking Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.connect(new InternetAddress("127.0.0.1", 444)); s.send("Foo!"); printf("Local=%.*s, Remote=%.*s\r\n", s.localAddress().toString(), s.remoteAddress().toString()); s.close(); +/ /+ //nonblocking with select() Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.blocking = false; assert(s.blocking == false); SocketSet sset = new SocketSet(1); sset.add(s); s.connect(new InternetAddress("127.0.0.1", 444)); printf("select=%d\r\n", Socket.select(null, sset, null, 1000)); //wait for connection s.send(cast(dchar[])"Foo!"); sset.reset(1);import socket; // dmd sockettest socket ws2_32.lib int main() { /+ //regular blocking Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.connect(new InternetAddress("127.0.0.1", 444)); s.send("Foo!"); printf("Local=%.*s, Remote=%.*s\r\n", s.localAddress().toString(), s.remoteAddress().toString()); s.close(); +/ /+ //nonblocking with select() Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.blocking = false; assert(s.blocking == false); SocketSet sset = new SocketSet(1); sset.add(s); s.connect(new InternetAddress("127.0.0.1", 444)); printf("select=%d\r\n", Socket.select(null, sset, null, 1000)); //wait for connection s.send(cast(dchar[])"Foo!"); sset.reset(1); sset.add(s); printf("select=%d\r\n", Socket.select(null, sset, null, 1000)); //wait for send printf("Local=%.*s, Remote=%.*s\r\n", s.localAddress().toString(), s.remoteAddress().toString()); s.close(); +/ /+ //nonblocking listen() with select() Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.blocking = false; SocketSet sset = new SocketSet(1); sset.add(s); s.bind(new InternetAddress(444)); s.listen(10); printf("select=%d\r\n", Socket.select(sset, null, null)); //wait for accept with(s.accept()) { printf("Accepted connection from %.*s\r\n", remoteAddress().toString()); close(); } s.close(); +/ //nonblocking connect() to 127.0.0.1 port 80 with select() and display web page Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.blocking = false; SocketSet sset = new SocketSet(1); sset.add(s); s.connect(new InternetAddress("66.35.250.210", 80)); //if(!Socket.select(null, sset, null, 3000000)) //3secs // throw new Exception("Connection timed out."); // else printf("ok select 1\n"); s.send("GET / HTTP/1.1\r\nHost: bzflag.org\r\n\r\n"); char[1024] buf; int read; for(;;) { sset.reset(1); sset.add(s); //if(Socket.select(sset, null, null, 1000000)) //{ read = s.receive(buf); if(read) { printf("%.*s", buf[0 .. read]); } else { printf("\r\n\r\nConnection closed.\n"); break; } //} //else //{ // printf("\r\n\r\nRead timeout."); // break; //} } s.close(); return 0; } sset.add(s); printf("select=%d\r\n", Socket.select(null, sset, null, 1000)); //wait for send printf("Local=%.*s, Remote=%.*s\r\n", s.localAddress().toString(), s.remoteAddress().toString()); s.close(); +/ /+ //nonblocking listen() with select() Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.blocking = false; SocketSet sset = new SocketSet(1); sset.add(s); s.bind(new InternetAddress(444)); s.listen(10); printf("select=%d\r\n", Socket.select(sset, null, null)); //wait for accept with(s.accept()) { printf("Accepted connection from %.*s\r\n", remoteAddress().toString()); close(); } s.close(); +/ //nonblocking connect() to 127.0.0.1 port 80 with select() and display web page Socket s = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.IP); s.blocking = false; SocketSet sset = new SocketSet(1); sset.add(s); s.connect(new InternetAddress("66.35.250.210", 80)); //if(!Socket.select(null, sset, null, 3000000)) //3secs // throw new Exception("Connection timed out."); // else printf("ok select 1\n"); s.send("GET / HTTP/1.1\r\nHost: bzflag.org\r\n\r\n"); char[1024] buf; int read; for(;;) { sset.reset(1); sset.add(s); //if(Socket.select(sset, null, null, 1000000)) //{ read = s.receive(buf); if(read) { printf("%.*s", buf[0 .. read]); } else { printf("\r\n\r\nConnection closed.\n"); break; } //} //else //{ // printf("\r\n\r\nRead timeout."); // break; //} } s.close(); return 0; } |
February 29, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix Attachments: | Here we go, Socket.select() is working on linux! Seems to be all good now.
--
Christopher E. Miller
|
February 29, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote:
> Here we go, Socket.select() is working on linux! Seems to be all good now.
>
Only change in socket.d
extern int errno; to -> extern (C) int errno;
at line 144
regards.
Julio Jiménez
|
February 29, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Julio Jiménez | Julio Jiménez wrote: > Vathix wrote: > >> Here we go, Socket.select() is working on linux! Seems to be all good now. >> > > Only change in socket.d > > extern int errno; to -> extern (C) int errno; > > at line 144 > > regards. > > > Julio Jiménez > It's already in an extern(C) block, and I think extern(C) is different from just extern.. -- Christopher E. Miller |
February 29, 2004 Re: Socket library for Win32 and Linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote: > Julio Jiménez wrote: > >> Vathix wrote: >> >>> Here we go, Socket.select() is working on linux! Seems to be all good now. >>> >> >> Only change in socket.d >> >> extern int errno; to -> extern (C) int errno; >> >> at line 144 >> >> regards. >> >> >> Julio Jiménez >> > > It's already in an extern(C) block, and I think extern(C) is different from just extern.. > Sorry, I'm wrong. I didn't realize extern was short for extern(D). -- Christopher E. Miller |
February 29, 2004 socket.d release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix Attachments: | I guess this one could be considered socket.d 1.0. I've tested it pretty well, even made a test server that accepts multiple connections, listener.d included. It works good for windows and linux.
Still needed:
- Host name resolving
- Socket stream class
--
Christopher E. Miller
|
Copyright © 1999-2021 by the D Language Foundation