473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

exiting a socket and reading a file queries

hi all,

here are my questions.

i have a server/client program and in order to connect i need to be authorised.

i have managed to type in the codes on client, send them over to server, compare them with known values and either accept or decline them.

however if i decline the authorisation i want to close the connection, how do i do this ?

this is what i have written, when i enter incorrect details i do get the printf statement in the else but the connection stays open.
[INCODE] if (status==1)
{
printf("you should continue\n");
printf("true = %d",status);
}
else
{
printf(" i am here but not closing\n");
close_socket(sock);
}
[/INCODE]

Also how can i read several lines of data from a file and store them to send over to my client. I need to search the file for matching criteria...i.e i have a list of tv programmes but i only want whats on on BBC 1.

Cheers for looking, any help would be greatly appreciated.
May 7 '07 #1
3 1059
svlsr2000
181 Expert 100+
Can you post your implementation for close_socket.

And if possible can you tell about your environment like operating system, compiler etc
May 7 '07 #2
Can you post your implementation for close_socket.


ermmm no, don't know what you mean ? all i have was in the code before, if my status from the check does not match then i want the socket to disconnect.

And if possible can you tell about your environment like operating system, compiler etc
ok i think i know this one. i am writing in C, via putty (ssh) to a university linux PC. the complier i believe is gcc.
May 7 '07 #3
svlsr2000
181 Expert 100+
Close system call is used to close a socket.
you have used close_socket, its a good practice not to use any system calls directly in c++.

If the socket being closed is associated with a protocol that promises reliable delivery (e.g., TCP or SPP), the system must assure that any data within the kernel that still has to be transmitted or acknowledged, is sent. Normally, the system returns from the close immediately, but the kernel still tries to send any data already queued.
May 8 '07 #4

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

Similar topics

1
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java...
4
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
3
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server...
3
by: Nagash01WS6 | last post by:
Im working on writing an FTP application in C# to get a good feeling for the .NET language and how threading / networking classes all work. Thus far I have it working for the most part in PASV...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
2
by: Sean | last post by:
Hi guys, I have a question. I am trying to write a simple echo program. The objective is to read in a file in chuncks into the buffer and transfer the buffer over the socket. We repeat this until...
4
by: Patrick Altman | last post by:
I am attempting to use a HEAD request against Amazon S3 to check whether a file exists or not and if it does parse the md5 hash from the ETag in the response to verify the contents of the file so...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.