From: B on 10 Jan 2010 08:18 Hi All, Fir of all, my huge apologies if I am posting this to the wrong group. Post it to C++ and I get complaints that this stuff is too specialised...So here goes: I have implemented a server -- client chat program to help me learn about sockets, pthreads, and openssl libraries. On one machine, Alice, the program runs in server mode On the other machine, Bob, the program runs in client mode Bob connects to Alice and both parties can chat to each other and send files to each other. There is also an encryption option which encrypts everything with a 256 bit symmetric blowfish key which is initially distributed using public key encryption (2048 bit RSA). Now, I have some strange problems with its operation. In encryption mode, when I run both client and server on localhost, everything works fine. However, when I run them on differnt machines e.g. over a lan or wan, the files end up becoming corrupted, although chat is still encrypted fine. How can it work fine on localhost yet not accross multiple machines? Any idea what the problem could be? I'm a beginner with this. The entire code for the whole application can be found at: http://pastebin.com/m4573a043 It requires wx widgets and openssl development libraries. Tested on mac and linux. It can be compiled with: g++ chatServer.cpp `wx-config --cxxflags` -lcrypto `wx-config --static=no --libs` -o chatServer Cheers, B.
From: Eric Sosman on 10 Jan 2010 08:56 On 1/10/2010 8:18 AM, B wrote: > [...] > Now, I have some strange problems with its operation. In encryption > mode, when I run both client and server on localhost, everything works > fine. However, when I run them on differnt machines e.g. over a lan or > wan, the files end up becoming corrupted, although chat is still > encrypted fine. > > How can it work fine on localhost yet not accross multiple machines? > [...] I have not looked at your code (I'm reluctant to click on links in Usenet posts unless I know something about them), but one of the pitfalls in TCP/IP communication is that read() and write() (or whatever you're using) don't always receive or send the entire batch of data in one lump. You can't just write() to a socket and say "That's that;" you've got to look at the returned value that tells you how many bytes were actually written, and perhaps try again (and again, and again) to send the additional bytes that weren't transmitted on the first try. Similarly with read(). Just a thought. Good luck! -- Eric Sosman esosman(a)ieee-dot-org.invalid
From: B on 10 Jan 2010 10:21 On 2010-01-10 13:56:01 +0000, Eric Sosman <esosman(a)ieee-dot-org.invalid> said: > On 1/10/2010 8:18 AM, B wrote: >> [...] >> Now, I have some strange problems with its operation. In encryption >> mode, when I run both client and server on localhost, everything works >> fine. However, when I run them on differnt machines e.g. over a lan or >> wan, the files end up becoming corrupted, although chat is still >> encrypted fine. >> >> How can it work fine on localhost yet not accross multiple machines? >> [...] > > I have not looked at your code (I'm reluctant to click on > links in Usenet posts unless I know something about them), but > one of the pitfalls in TCP/IP communication is that read() and > write() (or whatever you're using) don't always receive or send > the entire batch of data in one lump. You can't just write() > to a socket and say "That's that;" you've got to look at the > returned value that tells you how many bytes were actually written, > and perhaps try again (and again, and again) to send the additional > bytes that weren't transmitted on the first try. Similarly with > read(). > > Just a thought. Good luck! Thanks, I've actually fixed it now (nb. the code I pasted up was actually more buggy than I thought). If anyone wants the code, let me know. Cheers, B.
From: _JusSx_ on 10 Jan 2010 11:14 On 2010-01-10, B <B(a)home> wrote: > On 2010-01-10 13:56:01 +0000, Eric Sosman <esosman(a)ieee-dot-org.invalid> said: > >> On 1/10/2010 8:18 AM, B wrote: >>> [...] >>> Now, I have some strange problems with its operation. In encryption >>> mode, when I run both client and server on localhost, everything works >>> fine. However, when I run them on differnt machines e.g. over a lan or >>> wan, the files end up becoming corrupted, although chat is still >>> encrypted fine. >>> >>> How can it work fine on localhost yet not accross multiple machines? >>> [...] >> >> I have not looked at your code (I'm reluctant to click on >> links in Usenet posts unless I know something about them), but >> one of the pitfalls in TCP/IP communication is that read() and >> write() (or whatever you're using) don't always receive or send >> the entire batch of data in one lump. You can't just write() >> to a socket and say "That's that;" you've got to look at the >> returned value that tells you how many bytes were actually written, >> and perhaps try again (and again, and again) to send the additional >> bytes that weren't transmitted on the first try. Similarly with >> read(). >> >> Just a thought. Good luck! > > Thanks, I've actually fixed it now (nb. the code I pasted up was > actually more buggy than I thought). > If anyone wants the code, let me know. > Did you solve the problem with B's suggestion? Please let me know because I'm curious Thanks in advance -JusSx- -- Linux is only free if your time has no value
From: Eric =?utf-8?Q?B=C3=B6se-Wolf?= on 10 Jan 2010 12:21
I would like to get a copy of your code. My e-mail adress is valid. Eric |