473,785 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple TCP/IP server/client - help!

1 New Member
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:

Expand|Select|Wrap|Line Numbers
  1.  #!perl -w
  2. # Server Program
  3. use IO::Socket::INET;
  4. print ">> Server Program <<\n";
  5.  
  6. # Create a new socket
  7. $MySocket=new IO::Socket::INET->new(
  8.     LocalPort=>1234,
  9.     Proto=>'udp'
  10. );
  11.  
  12.  
  13. # Keep receiving messages from client
  14. $def_msg="\nReceiving message from client.....\n";
  15. $sum=0;
  16.  
  17. while(1)
  18. {
  19.         $MySocket->recv($number,128);
  20.         $sum=$sum+$number;
  21.         $MySocket->send($sum);
  22.  
  23.     if($number ne '0')
  24.     {
  25.         print "\nReceived message '", $number,"'\n";
  26.  
  27.     }
  28.     # If client message is empty exit
  29.     else
  30.     {
  31.         print "Cilent has exited!";
  32.         $MySocket->send($number);
  33.         exit 1;
  34.     }
  35. }
Client:
Expand|Select|Wrap|Line Numbers
  1. #!perl -w
  2. # Client Program
  3. use IO::Socket::INET;
  4. print ">> Client Program <<";
  5.  
  6. # Create a new socket
  7. $MySocket=new IO::Socket::INET->new(
  8.     PeerPort=>1234,
  9.     Proto=>'udp',
  10.     PeerAddr=>'localhost'
  11.     );
  12.  
  13. # Send messages
  14. $def_msg="client: ";
  15. print "\n",$def_msg;
  16. while($msg=<STDIN>)
  17. {
  18.     chomp $msg;
  19.     if($msg ne '0')
  20.     {
  21.  
  22.        if(print $MySocket($msg))
  23.         {
  24.             print "";
  25.         }
  26.         if($MySocket->recv($text,128))
  27.         {
  28.             print "\server: '", $text,"'\n";
  29.             print $def_msg;
  30.         }
  31.     }
  32.     else
  33.     {
  34.         # Send an empty message to server and exit
  35.         $MySocket->send('0');
  36.         exit 1;
  37.     }
  38. }
  39.  
  40.  
  41.  
Feb 7 '09 #1
2 5408
KevinADC
4,059 Recognized Expert Specialist
Did you try changing the protocol?

Proto=>'udp'
Feb 7 '09 #2
Icecrack
174 Recognized Expert New Member
First Off in the Client script on line 28.

Expand|Select|Wrap|Line Numbers
  1. print "\server: '", $text,"'\n";
  2.  
Should be:
Expand|Select|Wrap|Line Numbers
  1. print "Server: '", $text,"'\n";
  2.  

now for server code you don't need the var or line of:

Expand|Select|Wrap|Line Numbers
  1. $def_msg="\nReceiving message from client.....\n";
  2.  
if you want to use it add
Expand|Select|Wrap|Line Numbers
  1. print $def_msg;
in between the while and if statement.
Feb 9 '09 #3

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

Similar topics

1
9051
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.
3
2487
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 *
1
2708
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 :
10
2652
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...
7
1501
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...
18
3043
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 ??
0
2169
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...
2
5186
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
0
2206
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...
10
2139
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")_
0
10336
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, 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...
0
10155
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 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...
0
9953
tracyyun
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...
0
8978
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, 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...
1
7502
isladogs
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...
0
5383
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...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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
3
2881
bsmnconsultancy
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...

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.