473,748 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Server Socket & C++ Client Socket

Hi,
We have a socket server app in Java and the client application in C++.

When we try to connect 60 clients simultaneously from C++ using
threads, only 55-56 connections are successfull, rest are not
connected(Conne ction refused error).

For one connection everything works fine. In server side each
connection is handled in seperate thread.

Is there anything else to be done?

The server code is as follows.
public class SocketServer
{
public static void main(String args[])
{

ServerSocket Server = null;
Socket clientSocket = null;

try
{
Server = new ServerSocket(79 99,60);
}
catch (IOException e)
{
System.out.prin tln(e);
}

try
{
while (true)
{
clientSocket = Server.accept() ;
SocketThread objThread = new SocketThread(cl ientSocket);
objThread.start ();
}
}
catch (Exception e)
{
System.out.prin tln(e);
}
finally
{

try
{
Server.close();
}
catch (IOException e)
{
System.out.prin tln(e);
}
}

}
}
Jul 17 '05 #1
2 11292
On 28 May 2004 22:16:10 -0700, Rajesh wrote:
We have a socket server app in Java and the client application in
C++.

When we try to connect 60 clients simultaneously from C++ using
threads, only 55-56 connections are successfull, rest are not
connected(Conne ction refused error).

For one connection everything works fine. In server side each
connection is handled in seperate thread.

Is there anything else to be done?


You have likely run into an OS-imposed descriptor limit on the server.
You don't say what OS you are using, but on unix you can use ulimit to
check or modify the limit.

I was going to suggest that you look at changing the backlog in the
ServerSocket constructor (in case your clients are connecting too
quickly for the server to handle), but see now that you've already set
it to 60.

I assume that SocketThread closes the Socket when it's done handling
the client?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Jul 17 '05 #2
just because you have allocated 60 clients doesn't mean that the server
has to connect them all on the first try. connecting sockets is a
dynamic relationship... in otherwords if at first your client does not
succeed, get it to try again after so many seconds...

- perry
Rajesh wrote:
Hi,
We have a socket server app in Java and the client application in C++.

When we try to connect 60 clients simultaneously from C++ using
threads, only 55-56 connections are successfull, rest are not
connected(Conne ction refused error).

For one connection everything works fine. In server side each
connection is handled in seperate thread.

Is there anything else to be done?

The server code is as follows.
public class SocketServer
{
public static void main(String args[])
{

ServerSocket Server = null;
Socket clientSocket = null;

try
{
Server = new ServerSocket(79 99,60);
}
catch (IOException e)
{
System.out.prin tln(e);
}

try
{
while (true)
{
clientSocket = Server.accept() ;
SocketThread objThread = new SocketThread(cl ientSocket);
objThread.start ();
}
}
catch (Exception e)
{
System.out.prin tln(e);
}
finally
{

try
{
Server.close();
}
catch (IOException e)
{
System.out.prin tln(e);
}
}

}
}


Jul 17 '05 #3

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

Similar topics

0
2700
by: Dominique | last post by:
I am trying to communicate to a prolog server from a java client, however even though the connection is successfully made every time I try to perform QueryExecute I get an error, either Socket closed or null etc. Can anyone help? I am using SICStus prolog. Currently my prolog server looks like: :- write('starting'),nl. :- use_module(library(sockets)). :- use_module(library(prologbeans)). :- use_module(library(charsio)).
1
5431
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 server works OK. I've heard, that P2.3 has SSL support included in himself and also, I was trying P2.2 with pyOpenSSL wrappers and extensions, but unsuccesfuly... So, could you give me a few lines of python code which makes such things:
0
2784
by: netgeni59 | last post by:
Hello fellow C# friends, I am trying to write a C# TCP client that was formerly written in Java. The server must still remain in Java. I cannot get text data from the C# client to be received by the Java TCP server. No matter how I try to send data from the client to the server, the Java server DataInputStream readUTF() method never returns with any data. Can someone please shed some light on this problem? Thanks.
4
8200
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with TcpClient, NetworkStream and StreamWriter classes. but with low level socket it doesn't work (When using the Socket class Send method).
4
2137
by: mohana | last post by:
hi, i just want 2 communicate with the near by computer. i got this program from internet. i have two programs called Server.java and Client.java. i am putting that program here now, Server.java Program: import java.net.*; import java.io.*; public class Server
2
6499
by: happyvalley | last post by:
Hi, don't know if it is the place to ask this question I have a c++ server and a java client communicate via socket in Java client // create a client socket Socket clientSocket = new Socket("localhost", 27015); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
3
2642
by: akmkat | last post by:
Hi all, I am in a great problem. I am trying to implement a multithreaded server using java, first look at the code... /*------- Main Server (server.java)--------------*/ import java.io.* ; import java.net.* ; public class server {
3
11680
by: TsanChung | last post by:
I want to make a java TCP socket client to communicate with a TCP server socket on linux. Are there some sample C unix server and java client socket programs available? The Richard Stevens' "Unix network programming" book described a TCP server (tcpcliserv04.c) and client (tcpcli04.c). I compiled and executed them successfully as follows: $ tcpcliserv04 &
10
4250
by: Elaine121 | last post by:
Hi i've been batteling for hours and can't seem to find the problem. When my server runs and I press the connect button the gui freezes until the client gui is terminated.. only then the gui becomes active again and displays the messages. Here is my server code: import java.io.*; import java.net.*; public class serverForm extends javax.swing.JFrame { private PrintWriter output = null;
0
8823
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
9530
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
9238
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
8237
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
6793
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
6073
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
4593
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...
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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.