473,654 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

socket not sending or receiving data

hi,
I 'v e written both the server and client side socket programs in
perl( a very small one).My socket is created and shows that the
connection is established with the client.however I am not able to
receive data in server side.I think the client sends the data
properly.Someho w receive does not happen.
Can someone tell me what could be wrong?
My code is part of the sample programs available for socket prgmng in
the net.
Here is the code for both client.

Client:
# !;/usr/perl -w

#client part

use IO::Socket::INE T;
$sock = new IO::Socket::INE T(
PeerAddr => '130.10.5.76',
PeerPort => '7070',
Proto => 'tcp'
);
die "could not create client socket: $!\n" unless $sock;

print "$sock Hello there!\n";

#send message

print "enter message to be sent:";

#while($msg = <STDIN>){
$msg = <STDIN>;

chomp $msg;
if($msg ne ''){
print "\nsending message\n";
if($sock->send($msg)){
print "\ndone\n";
print $msg;
}
else{
print "message not sent\n";
}
}
close($sock);

print "socket closed\n";

############### ############### ###########

Server:
# !/usr/perl -w
#socket server

use IO::Socket::INE T;

#create,bind,li sten socket
$sock = new IO::Socket::INE T(
Localhost => '130.10.5.38',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could notcreate socket: $!\n" unless $sock;

print "socket created\n";
$new_sock = $sock->accept();
while(defined(< $new_sock>)) {
print $_;
}
print "$new_sock" ;

$msg = "\nReceivin g message\n";
#while(1){

if($new_sock->recv($text,4)) {
if($text ne ''){
print "\nMessage received\n";
print $text;
}
else{
print "\nMessage is null\n";
print $text;
}
}
else{
print "\nReceive not success\n";
}
#}

close($sock);
close ($new_sock);
print "server socket closed";

regards & thanx,
AV
Jul 19 '05 #1
0 2345

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2625
by: Aaron | last post by:
tcpclient socket webrequest what are each used for? I read some reference books and did some research on the internet, but I'm still confused. could someone clarify this for me? Thanks, Aaron
3
4626
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
3
3693
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I tried this I don't see any diffents, I am sending 10Mb and the Send/BeginSend command doesn't wait till the data is on the remotepoint. Can somebody pls. explain this. Regards Robert.
2
15322
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I now see the socket.RecieveTimeout 'property' in the visual studio 2005 help documentation (framework 2.0) and it has example of it being used with TCP socket. This propery is also listed as 'new in .net 2.0'. 1) is the socket.RecieveTimeout...
7
9698
by: Ole | last post by:
Hi, I'm going to develop a socket communication between an instrument (running CE 5.0 with Compact Fraework V2) and a PC. As the instrument should only connect to one PC at a time I believe that the sync version of the socket should be the easiest - or what??? (please tell if I'm wrong). Are there anyone who is able to point to a Server and Client example code in C# VS2005 (I've only been able to find a C++ version) ???
3
4291
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
9
4294
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send some packets in response to the programs first message, but when I receive a response back, it's the last packet I sent. After that packet, I receive the packet I really wanted. This only happens when I connect with local host. I tried...
7
3176
by: darthghandi | last post by:
I am having mixed results with asynchronous socket receives. Sometimes I get the right information back from the buffer, other times I get some of the data that should be in the buffer printed out to the console. That data is printed out to the console before I even call Socket.EndReceive(). After that call, I get the rest of the data that wasn't printed out to the console in the buffer. Anyone have any idea what is going on? Here's...
4
7062
by: Zytan | last post by:
This may be the dumbest question of all time, but... When I set the packet size, does it mean ALL packets are that size, no matter what? Let's say the packet size is 8KB, and I send a 5 byte "hello", will it cause 8KB of bandwidth, or 5 bytes (plus TCP/IP packet header, as well, of course). (Btw, I 'set' the packet size via Socket.BeginReceive(), in the "size" field = "The number of bytes to receive." Which seems to imply the answer...
1
7155
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN site, which is actually for sending strings. I tried to adapt this code so that the client sends an image instead of a string. However, there is something wrong on the server side (i guess)... The server starts listening, the client starts sending...
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
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...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
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
7304
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...
0
5621
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1592
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.