Hello
I am very new to perl, however i managed to make this server/client work with udp, now i would like to do the same thing but with TCP/IP, what must i do?
Server: - #!perl -w
-
# Server Program
-
use IO::Socket::INET;
-
print ">> Server Program <<\n";
-
-
# Create a new socket
-
$MySocket=new IO::Socket::INET->new(
-
LocalPort=>1234,
-
Proto=>'udp'
-
);
-
-
-
# Keep receiving messages from client
-
$def_msg="\nReceiving message from client.....\n";
-
$sum=0;
-
-
while(1)
-
{
-
$MySocket->recv($number,128);
-
$sum=$sum+$number;
-
$MySocket->send($sum);
-
-
if($number ne '0')
-
{
-
print "\nReceived message '", $number,"'\n";
-
-
}
-
# If client message is empty exit
-
else
-
{
-
print "Cilent has exited!";
-
$MySocket->send($number);
-
exit 1;
-
}
-
}
Client: -
#!perl -w
-
# Client Program
-
use IO::Socket::INET;
-
print ">> Client Program <<";
-
-
# Create a new socket
-
$MySocket=new IO::Socket::INET->new(
-
PeerPort=>1234,
-
Proto=>'udp',
-
PeerAddr=>'localhost'
-
);
-
-
# Send messages
-
$def_msg="client: ";
-
print "\n",$def_msg;
-
while($msg=<STDIN>)
-
{
-
chomp $msg;
-
if($msg ne '0')
-
{
-
-
if(print $MySocket($msg))
-
{
-
print "";
-
}
-
if($MySocket->recv($text,128))
-
{
-
print "\server: '", $text,"'\n";
-
print $def_msg;
-
}
-
}
-
else
-
{
-
# Send an empty message to server and exit
-
$MySocket->send('0');
-
exit 1;
-
}
-
}
-
-
-
2 5408 KevinADC 4,059
Recognized Expert Specialist
Did you try changing the protocol?
Proto=>'udp'
Icecrack 174
Recognized Expert New Member
First Off in the Client script on line 28. -
print "\server: '", $text,"'\n";
-
Should be: -
print "Server: '", $text,"'\n";
-
now for server code you don't need the var or line of: -
$def_msg="\nReceiving message from client.....\n";
-
if you want to use it add
in between the while and if statement.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Johannes Eble |
last post by:
Hello Python community,
I am trying the echo-client and echo-server examples in Chapter 10,
"Programming Python" by Mark Lutz.
It is probably the most simple sockets sample: A socket server just
echoing the socket clients' requests.
The program works so far. I first start the server in one dos box,
then the client in another dos box on my machine.
|
by: MBW |
last post by:
The following code is for a simple server/client asplication that
allows the user to toggle between serve and or client modes and
send/recieve a message however i am getting an Attribute error on my
entry widgets when I try and call get() to get the port and ip address
from those fields, I'm sure it's something simple I haven't grasped...
#START
from Tkinter import *
from socket import *
|
by: Chris |
last post by:
Hi,
how do I develop the following 'simple' program using ASP.NET webforms :
a client has a text-file (aaa.txt) that has to be manipulated by code
located on the server, the server would then manipulate the content and send
the manipulated content back to the client, where the client saves it to
(bbb.txt)
What scenario would be best :
|
by: GeekBoy |
last post by:
Okay, I have two identical web servers running Windows 2003 web
server. I have an ASP.NET application which runs great on one of
them. Dedicated IP address, behind our firewall, etc. Everyone's
happy.
Now -- how do I take advantage of that second computer to
"load-balance" the web site? Will it really give my users a noticable
performance increase? How do you accomplish this? I've read many of
those MS articles and it's...
|
by: Steven |
last post by:
Hello,
First, let me state that I am trying to learn asp.net, so I am a beginner.
Now on to the issue. I have a webform with a single Textbox and a
FileSystemWatcher monitoring a directory for OnCreate events. I am trying
to change the text in response to an OnCreate event. I would like to change
the Forecolor to red, from black. Apparently, this is not as easy to do as
in vb.net. I have tried the direct approach in the OnCreate...
| |
by: Q. John Chen |
last post by:
I have Vidation Controls
First One: Simple exluce certain special characters:
say no a or b or c in the string:
*
Second One:
I required date be entered in "MM/DD/YYYY" format:
//+4 How ??
|
by: Harley |
last post by:
Hello,
I am just learning the tcp/ip functions etc under vb.net so please
look over me if this is obviouse. I have been all over looking into
any functions that I didn't totaly understand and can't see that I am
doing anything wrong (i obviousely am though)
everything "works", client connects to server and when anything is
sent to the server it starts the mp3 and passes all messages the way i
ment for it to except that my server is...
|
by: Vitali Gontsharuk |
last post by:
Hi!
I have a problem programming a simple client-server game, which is
called pingpong ;-)
The final program will first be started as a server (nr. 2) and then as
a client. The client then sends the message "Ping" to the server, which
reads it and answers with a "Pong".
The game is really simple and the coding should be also very simple! But
for me it isn't.
By the way, the program uses datagram sockets (UDP). And, I'm using
|
by: Grzegorz Smith |
last post by:
Hi All. I 'm learning ZSI to use SOAP and I desperately need help. I'm
working on example from tutorial -(examples/server/send_response/
simple/wsdl/).
Here are my wsdl files -http://pastebin.com/873488.
I made wsdl2py wsdl2py --complexType --file=binding.wsdl and get
Example_services.py and Example_Services_types.py.
Here is the Example_services.py -http://pastebin.com/873492
and Example_Services_types.py -http://pastebin.com/873494
Now...
|
by: Phillip Taylor |
last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm
having some trivial issues. In Visual Studio I create a web services
project and change the asmx.vb file to this:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Services.WebService(Namespace:="http://
wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |