Sponsored Content
Top Forums Programming Write the source code for messenger Post 302094196 by nathan on Thursday 26th of October 2006 12:25:31 AM
Old 10-26-2006
I'm actually trying to do the same thing (write a simple instant messenger program) but am running into a few problems.

Right now I am just focusing on the "communication" portion, using a command-line interface. I plan to add the GUI stuff later.

I am using C++ and the sockets api and have taken the approach of building both a "Server" and "Client" class. I have designed my instant messaging application to have both the server and client in one executable program.

So, in my main() function, I will:
1) Create an instance of Server ( for example, "Server my_serv( ); " )
2) Create an instance of Client ( for example, "Client my_cli( ); " )
3) Start the server ( for example, my_serv.start() )
4) Client stuff... ( connect to remote computer, enter text data to send, etc ).

One problem I have run into with this approach:

I attempt to start the server then use the client functionality, but then my program hangs, because the socket program is listening for a connection. ( I've tried non-blocking IO with the fcntl call below ).
This bit just gets all current flags for the file descriptor sd1, then adds the O_NONBLOCK flag to it.
Code:
  rc |= fcntl( sd1 , F_SETFL , ((fcntl( sd1 , F_GETFL ))|O_NONBLOCK) );

I believe I might need to use the select() function, but I'm not sure if I'm headed down the wrong path.

Would it be best to split this up into 2 programs ( i.e. one as a server and the other as a client )? Or could (should?) I use fork(), start the server in one process, then the client in the other? (I've tried the fork()ing approach, but had some problems.)

I'm trying to get an idea of how the program would be best designed. Any ideas are appreciated.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where can I review the source code?

A very n00b question: After compiling and installing software, where does the original source code reside? I'd like to study the source code of some of the ports I've installed. Thanks! :D (1 Reply)
Discussion started by: Aaron Van
1 Replies

2. Shell Programming and Scripting

write page source to standard output

I'm new to PERL, but I want to take the page source and write it to a file or standard output. I used perl.org as a test website. Here is the script: use strict; use warnings; use LWP::Simple; getprint('http://www.perl.org') or die 'Unable to get page'; exit 0; ... (1 Reply)
Discussion started by: wxornot
1 Replies

3. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

4. UNIX for Dummies Questions & Answers

Where can i get unix source code?

Sir please tell me where can i get source code for some unix kernal and shell also. (1 Reply)
Discussion started by: VIPUL15
1 Replies

5. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

6. Linux

Source code

I need the source code of fedora. plz plz plz help me........... (1 Reply)
Discussion started by: neh
1 Replies

7. Shell Programming and Scripting

Source code compilation

Need assistance in Source code compilation . When installing a software compiling a source code . Whatever the output that prints on the screen i want to log it into a file. How can i see output and store the output to file ./configure make make install Is there other way of seeing output... (5 Replies)
Discussion started by: ajayram_arya
5 Replies

8. UNIX for Dummies Questions & Answers

Source code

hii... i am a biginner....and i have linux source code ,downloaded from some website ,a compressed file on windows and dont know how do compile them..... (4 Replies)
Discussion started by: M K Raju
4 Replies
Mail::SpamAssassin::Client(3)				User Contributed Perl Documentation			     Mail::SpamAssassin::Client(3)

NAME
Mail::SpamAssassin::Client - Client for spamd Protocol SYNOPSIS
my $client = new Mail::SpamAssassin::Client({ port => 783, host => 'localhost', username => 'someuser'}); or my $client = new Mail::SpamAssassin::Client({ socketpath => '/path/to/socket', username => 'someuser'}); Optionally takes timeout, which is applied to IO::Socket for the initial connection. If not supplied, it defaults to 30 seconds. if ($client->ping()) { print "Ping is ok "; } my $result = $client->process($testmsg); if ($result->{isspam} eq 'True') { do something with spam message here } DESCRIPTION
Mail::SpamAssassin::Client is a module which provides a perl implementation of the spamd protocol. PUBLIC METHODS
new public class (Mail::SpamAssassin::Client) new (\% $args) Description: This method creates a new Mail::SpamAssassin::Client object. process public instance (\%) process (String $msg) Description: This method calls the spamd server with the PROCESS command. The return value is a hash reference containing several pieces of information, if available: content_length isspam score threshold message check public instance (\%) check (String $msg) Description: The method implements the check call. See the process method for the return value. headers public instance (\%) headers (String $msg) Description: This method implements the headers call. See the process method for the return value. learn public instance (Boolean) learn (String $msg, Integer $learntype) Description: This method implements the learn call. $learntype should be an integer, 0 for spam, 1 for ham and 2 for forget. The return value is a boolean indicating if the message was learned or not. An undef return value indicates that there was an error and you should check the resp_code/resp_msg values to determine what the error was. report public instance (Boolean) report (String $msg) Description: This method provides the report interface to spamd. revoke public instance (Boolean) revoke (String $msg) Description: This method provides the revoke interface to spamd. ping public instance (Boolean) ping () Description: This method performs a server ping and returns 0 or 1 depending on if the server responded correctly. PRIVATE METHODS
_create_connection private instance (IO::Socket) _create_connection () Description: This method sets up a proper IO::Socket connection based on the arguments used when creating the client object. On failure, it sets an internal error code and returns undef. _parse_response_line private instance (@) _parse_response_line (String $line) Description: This method parses the initial response line/header from the server and returns its parts. We have this as a separate method in case we ever decide to get fancy with the response line. _clear_errors private instance () _clear_errors () Description: This method clears out any current errors. _filter private instance (\%) _filter (String $msg, String $command) Description: Makes the actual call to the spamd server for the various filter method (ie PROCESS, CHECK, HEADERS, etc). The command that is passed in is sent to the spamd server. The return value is a hash reference containing several pieces of information, if available: content_length isspam score threshold message (if available) perl v5.12.1 2010-03-16 Mail::SpamAssassin::Client(3)
All times are GMT -4. The time now is 05:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy