473,473 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

converting normal server to multi-client one

31 New Member
I have normal server code here, and i have no idea how to make it work with many clients. The server would print what one client says to every client.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use IO::Socket::INET;
  3. use strict;
  4.  
  5. my $port = '1584';
  6.  
  7. my $socket = IO::Socket::INET->new('LocalPort' => $port,
  8.                                    'Proto' => 'tcp',
  9.                                    'Listen' => SOMAXCONN)
  10.     or die "Can't create socket ($!)\n";
  11. print "[Server created at port:$port]\n";
  12. while (my $client = $socket->accept) {
  13. $client->autoflush(1);
  14.     my $name = gethostbyaddr($client->peeraddr, AF_INET);
  15.     printf "[Connect from %s]\n", $client->peerhost;
  16.     my $port = $client->peerport;
  17.     while (<$client>) {
  18.         print "[$name $port] $_";
  19.         print $client "[$name $port] $_";
  20.     }
  21.     close $client
  22.         or die "Can't close ($!)\n";
  23. }
  24. die "Can't accept socket ($!)\n";
Oct 19 '08 #1
9 3427
KevinADC
4,059 Recognized Expert Specialist
This seems like a script kiddy, script at least part of it,

and from the previous post he/she has posted it looks like it,
I am not sure what a script kiddy is or what your implication is. The code looks benign to me, I don't know how to answer his question though.
Oct 20 '08 #2
Icecrack
174 Recognized Expert New Member
Can i ask what is this being used for, and we don't understand what you mean
Oct 20 '08 #3
über
31 New Member
im making a chat script so clients can connect to one server and speak in there, now it works with only with 2 persons so every person who want chat would need to make own servers and get the own clients to other person servers
and then the desktop will be full of those command prompt windows
Oct 20 '08 #4
Icecrack
174 Recognized Expert New Member
im making a chat script so clients can connect to one server and speak in there, now it works with only with 2 persons so every person who want chat would need to make own servers and get the own clients to other person servers
and then the desktop will be full of those command prompt windows

is that the whole script??, i would like to look at the client script
because from what i have followed up on this it should accept more then one connection.
Oct 21 '08 #5
über
31 New Member
Here is the client script
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #didnt make this
  3. use IO::Socket::INET;
  4. use strict;
  5.  
  6. my $name = 'localhost';
  7. my $port = '1584';
  8.  
  9. my $socket = IO::Socket::INET->new('PeerAddr' => $name,
  10.                                    'PeerPort' => $port,
  11.                                    'Proto' => 'tcp')
  12.     or die "Can't create socket ($!)\n";
  13. print "Client sending\n";
  14. while (<STDIN>) {
  15.     print $socket $_;
  16.     print scalar <$socket>;
  17. }
  18. close $socket
  19.     or die "Can't close socket ($!)\n";
The problem is when i connect the server with 2 clients, the server prints that "127.0.0.1 has connected" only once and when i try to send something with the other client the server wont print it
Oct 21 '08 #6
Icecrack
174 Recognized Expert New Member
Here is the client script
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #didnt make this
  3. use IO::Socket::INET;
  4. use strict;
  5.  
  6. my $name = 'localhost';
  7. my $port = '1584';
  8.  
  9. my $socket = IO::Socket::INET->new('PeerAddr' => $name,
  10.                                    'PeerPort' => $port,
  11.                                    'Proto' => 'tcp')
  12.     or die "Can't create socket ($!)\n";
  13. print "Client sending\n";
  14. while (<STDIN>) {
  15.     print $socket $_;
  16.     print scalar <$socket>;
  17. }
  18. close $socket
  19.     or die "Can't close socket ($!)\n";
The problem is when i connect the server with 2 clients, the server prints that "127.0.0.1 has connected" only once and when i try to send something with the other client the server wont print it
I'm Testing your code will get back to you shortly,

thanks
Oct 22 '08 #7
Icecrack
174 Recognized Expert New Member
I'm Testing your code will get back to you shortly,

thanks

sorry im still looking at your code and testing this...
Oct 24 '08 #8
KevinADC
4,059 Recognized Expert Specialist
The code should not compile, I spotted at least one syntax error:

Expand|Select|Wrap|Line Numbers
  1. print $socket $_;
That should probably be:

Expand|Select|Wrap|Line Numbers
  1. print "$socket $_";
Oct 24 '08 #9
Icecrack
174 Recognized Expert New Member
The code should not compile, I spotted at least one syntax error:

Expand|Select|Wrap|Line Numbers
  1. print $socket $_;
That should probably be:

Expand|Select|Wrap|Line Numbers
  1. print "$socket $_";

it does compile Kevin, i have tested it, i think its more to do with the port being used on one computer im trying to test this not on the same machine (Server on one, 2 clients on 2 other machines)
Oct 25 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: j.a. harriman | last post by:
Hi, On MSDN I know there is a JScript example (Upgrading Visual C++ Projects to Visual Studio .NET in Batch Mode) to upgrade VS6 C++ projects to .NET solutions. It converts the project files...
14
by: D | last post by:
Hey guys- not sure where this post fits in, so I cc'd a few other groups as well- hope you dont mind... I have someone creating a database for me in Access 2000 (or is it called XP?). When it's...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
3
by: Klaus Jensen | last post by:
Hi! In this code...: Dim oAsciiStreamWriter As New StreamWriter("C:\Temp\TestAscii.txt", False, System.Text.ASCIIEncoding.ASCII) oAsciiStreamWriter.WriteLine("Test of danish chars - ÆØÅæøå")...
3
by: Sharon | last post by:
I have a buffer of byte that contains a raw data of a 1 byte-per-pixel image data. I need to convert this buffer to a Bitmap of Format32bppArgb and to a Bitmap of Format24bppRgb. Can anybody...
4
by: Man-wai Chang | last post by:
Must I use CSS to layout the pages? -- .~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Ubuntu 6.06) ...
17
by: shineofleo | last post by:
Here is the situation: I wrote a VB programm, which stores all the information in a single Access database file using jet engine. It worked well, however one of my customs reported that there was...
2
by: DBuss | last post by:
OK, I'm reading a multicast socket. It attaches fine, reads fine, all of that. The problem is that while some of the data I get is normal text (ASCII String), some of it is Binary Integer. ...
10
by: John Brown | last post by:
Hi there, Does anyone know how to go about reading/writing a type to a file in a language (culture) independent way. For instance, let's say you're dealing with the native "System.Drawing.Size"...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.