Sponsored Content
Top Forums Programming Write the source code for messenger Post 302094985 by Corona688 on Thursday 2nd of November 2006 10:54:55 AM
Old 11-02-2006
pthreads means POSIX threads. POSIX is a standard which means that POSIX threads, among many other things, work the same way across many different UNIX and UNIX-like systems.

For the third time, I'd suggest simplifying the problem before you even begin to think about concurrency. Don't build a chat server, build a communication library. Build sets of tiny, tiny example programs; one pair where the server sends and the client recieves, another where the client sends and the server recieves, another where the client connects to what you name instead of anything builtin, etc. These don't have to be interactive, so you don't have to worry about user input and network input at the same time; you can get them working without worrying about threads. Once you perfect sending, recieving, and connecting, then you can put the puzzle pieces together in a multithreaded application.

I understand the temptation to skip all that and build a simple something without any framework, but when you get into it, these "simple" things inevitably become way more complicated than they first appear. If you don't break it down, you won't be able to understand what you've written after leaving it for a week.

Last edited by Corona688; 11-02-2006 at 12:08 PM..
 

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
Wx::Socket(3)						User Contributed Perl Documentation					     Wx::Socket(3)

NAME
Wx::Socket - wxSocket* classes USAGE
use Wx qw(:socket) ; use Wx::Event qw(EVT_SOCKET_INPUT EVT_SOCKET_LOST) ; use Wx::Event qw(EVT_SOCKET_CONNECTION) ; ########## # CLIENT # ########## my $sock = Wx::SocketClient->new(wxSOCKET_WAITALL); EVT_SOCKET_INPUT($parent , $sock , &onInput ) ; EVT_SOCKET_LOST($parent , $sock , &onClose ) ; $sock->Connect('localhost',5050) ; if (! $sock->IsConnected ) { print "ERROR " ;} sub onInput { my ( $sock , $this , $evt ) = @_ ; my $length = 123; my $buffer ; $sock->Read($buffer , 1024 , $length ) ; } ########## # SERVER # ########## my $sock = Wx::SocketServer->new('localhost',5050,wxSOCKET_WAITALL); EVT_SOCKET_CONNECTION($parent , $sock , &onConnect ) ; if ( !$sock->Ok ) { print "ERROR " ;} sub onConnect { my ( $sock , $this , $evt ) = @_ ; my $client = $sock->Accept(0) ; my ($local_host,$local_port) = $client->GetLocal ; my ($peer_host,$peer_port) = $client->GetPeer ; $client->Write("This is a data test! ") ; ... or ... $client->Write( $data , length($data) ) ; $client->Close ; } METHODS
All the methods work as in wxWidgets (see the documentation). The functions for reading data (Read, ReadMsg, Peek) take 3 arguments, like the Perl read() function: ## To read the data into the variable $sock->Read($buffer , 1024) ; ... or ... ## To append data at the given offset: $sock->Read($buffer , 1024 , $offset ) ; The write functions (Write, WriteMsg, Unread) can be used with 1 or 2 arguments: $client->Write("This is a data test! ") ; $client->Write($data , $length) ; EVENTS
The events are: EVT_SOCKET EVT_SOCKET_ALL EVT_SOCKET_INPUT EVT_SOCKET_OUTPUT EVT_SOCKET_CONNECTION EVT_SOCKET_LOST The EVT_SOCKET works as in wxWidgets, the others are wxPerl extensions. Note that EVT_SOCKET events of wxSocketClient and wxSocketServer work differently than other event types. First you need to set the event handler: $sock->SetEventHandler($handler, $id) ; Then you set what types of event you want to receive: ## this select all. $sock->SetNotify(wxSOCKET_INPUT_FLAG|wxSOCKET_OUTPUT_FLAG| wxSOCKET_CONNECTION_FLAG|wxSOCKET_LOST_FLAG) ; Enable the event notification: $sock->Notify(1) ; And only after this use: ## note that $handler must be the same that was used in ## SetEventHandler EVT_SOCKET($handler, $id , sub{...} ) To make the events easier to use, all the proccess is automatic, and you just use: EVT_SOCKET_INPUT($handler , $socket , sub{...} ) EVT_SOCKET_OUTPUT($handler , $socket , sub{...} ) EVT_SOCKET_CONNECTION($handler , $socket , sub{...} ) EVT_SOCKET_LOST($handler , $socket , sub{...} ) ## This is for the events not used yet by the above: EVT_SOCKET_ALL($parent , $socket , sub{...} ) ** The new way is better to handle more than one socket in the same time too. Take a look in the demos. SEE ALSO
Wx, The wxWxwindows documentation at <http://www.wxwindows.org/> AUTHOR
Graciliano M. P. <gm@virtuasites.com.br> COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2007-06-18 Wx::Socket(3)
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy