GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Jul-2005, 12:27
L7Sqr L7Sqr is online now
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

[Program/Tutorial] Sockets to send messages


[Name] none
[Description] Example of creating a server and client for a simple message relay
[Date of Submit] July 27, 2005
[Submitter] L7Sqr
[License] none - free to use/copy/modify
[Detail] -
[Problems/Limitations] Files are compressed with 'tar -czv' and can be uncompressed with 'tar -xzvf socket.tar.gz' (the v is optional). A makefile is included. Program compiles with -ansi flag (no errors) although that flag is not included in the make. System specifics can be found in the file headers. Designed on a Linux system. Must be able to create /tmp/sample_chat.d as-is, but that can be modified pre-compile


NOTE: Due to extension reasons, the file has been renamed socket.zip...But IT IS NOT A ZIP FORMAT!!!

Included files

ipc_server.c:
Uses the following functions:
CPP / C++ / C Code:
socket (int, int, int);
unlink (const char *);
bind (int, struct sockaddr *, socklen_t);
listen (int, int)
accept (int, struct sockaddr *, socklen_t *);
select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
recv (int, void *, size_t, int);
close (int);

ipc_client.c:
Uses the following functions:
CPP / C++ / C Code:
socket (int, int, int);
connect (int, const struct sockaddr *,  socklen_t);
write (int, void *, size_t);
close (int);

sample_ipc.h:
Containes the following (all of which can be 'tweaked')
CPP / C++ / C Code:
#define LISTENQ 10
#define path "/tmp/sample_chat.d"

typedef struct {
   char name[20];
   char msg[255];
} message_t;

makefile:
Compiles using the following
CPP / C++ / C Code:
cc -o server -Wall -W -pedantic -g ipc_server.c
cc -o client -Wall -W -pedantic -g ipc_client.c


Use
Open two consoles. In the directory containing the executables run ./server in one and ./client in the other.


Sample output:
Console #1: (client)
CPP / C++ / C Code:
[CLIENT] : I am the client\n
[CLIENT] : Sending a test\n
[CLIENT] : ^C
Console #2: (server)
CPP / C++ / C Code:
[SERVER] Name: 'Client'
[SERVER] Data: I am the client
-------------
[SERVER] Name: 'Client'
[SERVER] Data: Sending a test
recv error...Aborting
Attached Files
File Type: zip socket.zip (2.4 KB, 182 views)
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
windows sockets confusion ubergeek C++ Forum 1 18-Jul-2005 21:44
I can not view my private messages and my signature...is this normal? metamorph GIDForums™ 3 26-Feb-2004 05:41
send email via local intranet skyloon MySQL / PHP Forum 1 30-Jun-2003 08:15

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:11.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.