help: problem with sockets write/read


 
Thread Tools Search this Thread
Top Forums Programming help: problem with sockets write/read
# 1  
Old 11-29-2011
help: problem with sockets write/read

I am trying to make a server and client, the client will choose between some options and the server will react accordingly.

After a some reads and writes that work the server needs to read from client an INT i use this:

Code:
read(newSd,&k,sizeof(int));

But even if all the other times there was no problem
this time the server does not seem to block on read OR it reads something but without the client sending.I also wrote multiple reads in server after this one and no writes in client, still the server passed through them to the next lines of code.

What could cause this?
# 2  
Old 11-29-2011
If it reads without the client sending, then there was data there waiting to be read which you didn't read before. You couldn't have been reading all the data the client sent.

Also, you should use send/recv for sockets, not read/write, though that wouldn't cause this problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Partial Write for sockets in LINUX

We have a server-client communication in our application. Sockets are used for the communication. We are using AF_INET sockets with SOCK_STREAM(TCP/IP). Also these sockets are in Non Blocking mode (O_NONBLOCK). Application is written in C++ on UNIX. In our system the Server will write to a... (4 Replies)
Discussion started by: sanushchacko
4 Replies

2. Red Hat

How can I monitor network in CentOS .5.5 , my application refuse to read sockets

Hi I have wired problem with one of my applications (servers ) , its suddenly starts to read socket and before it written back , the connection is closed this is what I see in my logs . is there any took in Linux centos that lets me see what is happening in this time frame ? (1 Reply)
Discussion started by: umen
1 Replies

3. Programming

c++, raw sockets, stopping kernel write in header?

Hi, im trying to lern about raw sockets with my debian and c++. Tried to make a icmp and tcp packet and send it with sendto. Checked on wireshark and recognized that kernel changed my headers. So searched about stopping the kernel change the header and tried it with setsockopt, like said in at this... (4 Replies)
Discussion started by: sandcastle
4 Replies

4. UNIX for Dummies Questions & Answers

is there any problem with functions and sockets?

hi I am writing a client-server program and the functions I've written on the server are never executed. even something as easy as typing hello does not. is there something to be taken into account to use functions? I appreciate any information (2 Replies)
Discussion started by: oticeip
2 Replies

5. 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

6. Programming

problem with lots of open sockets

I'm programming in C with lots of sockets, (asynchronous handling), and for a while it goes ok, but after a while it starts to hang, or not get complete connections anymore. checking my router, i see that i get nat tables overflow and even my DNS cacher seems to be having serious issues... ... (4 Replies)
Discussion started by: alien999999999
4 Replies

7. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

8. Programming

Problem in file transfer using sockets

Hai Friends I am writing a c program to transfer files from one system to another using TCP/IP socket programming.. My Recieve Program #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> extern int errno; extern char *sys_erlist; void... (2 Replies)
Discussion started by: collins
2 Replies

9. Programming

Problem with read & write

Hello mates: I met problem with using read() & write(). I m trying to use read twice on client first time is the size of buffer, 2nd time is the buffer. I think I have to, coz I dnot know file size. So, I write twice on server as well -- 1st, filesize; 2nd, buffer. The problem is, sometimes,... (11 Replies)
Discussion started by: EltonSky
11 Replies

10. Programming

popening for read and write

How can 'popen()' be used for reading and writing to opening pipe? If i try 'popen("prog", "rw")' and then put and get chars - it does not work. What is wrong? (1 Reply)
Discussion started by: szzz
1 Replies
Login or Register to Ask a Question