473,383 Members | 1,892 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,383 software developers and data experts.

Socket between two threads

3
I'm not sure this is even possible, but I am hoping there may be some way to do this:

I have two threads in a single application. One is an application that I am developing connects via a socket to another system running some other software. I am writing a simulator to provide a means of testing my application without having access to the other system (which I rarely have access to).

I want the simulator to be completely transparent, but I want to be able to control it within my application to ease development (e.g. I simply want a tab in my GUI to control this simulator). What I mean is the simulator and the application MUST communicate via a socket.

The issue is that sockets are designed for communication between two different processes. Can I use a socket between the app thread and the simulator thread in my single process?
Jul 17 '08 #1
5 5121
have you ever tried? I do not see any problem that you can't. You may use the network socket for sure for this in C++. One of them is listening on a specific port and the other one send messages to that port... as long as you have not both threads listening on same port things should be fine I suppose.
Jul 17 '08 #2
jhaws
3
Okay, to answer my own question:

I tried creating two threads in a single application, created the socket, and tried to write to and read from the socket.

The results were not good. Writing to the socket or reading from the socket caused the program to crash. It looks like I won't be able to do this.

If anyone has gotten this to work, please let me know. Otherwise I am off to find an alternate solution.
Jul 17 '08 #3
Banfa
9,065 Expert Mod 8TB
I have to say that when I write a simulator for a server application that my program is going to talk to I generally write a separate program. I mean the actual application will not need that simulator code 99% of the time it is in use so why burden it and bloat it by putting it in the same application/process.

Create a separate application to be the simulator.


However if you really want to go ahead with a single application then this
I tried creating two threads in a single application, created the socket, and tried to write to and read from the socket.
is wrong. Don't create a single socket and try to read and write from it that isn't how sockets work.

You need to create 2 sockets, first create the listen socket (for the server sim), then create the application socket and use it to connect to the listening socket.
Jul 18 '08 #4
jhaws
3
Create a separate application to be the simulator.
I agree with that. However, in this case the simulator is what our company will use to test our application because we only have access to the real system about once or twice a year (we are in Utah and it is in Virginia). For this reason I was hoping to make the simulator a subset of the application.

However, I think found a workaround. The simulator will be a separate application, but I think I am going to simply spawn another process from the main application when I need to run the simulator. That way I still have control of the simulator from the main user interface, but the socket problem is a lot easier.

Thanks for the help!
Jul 18 '08 #5
gpraghuram
1,275 Expert 1GB
If you create a detached thread and inside the thread fnction you open a socket and handle the communication i think it will be fine.
Also i have tried multi-threaded program with socket and i havent found tis type of issue

Raghu
Jul 21 '08 #6

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

Similar topics

6
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, Socket class documentation says that it is not thread safe. We understand that if do simultaneous sends on ONE socket then it will be a problem (or simultaneous receive). Can we create TWO...
9
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once...
5
by: Russell Warren | last post by:
Does anyone know the scope of the socket.setdefaulttimeout call? Is it a cross-process/system setting or does it stay local in the application in which it is called? I've been testing this and...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
2
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting...
2
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If...
13
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
0
by: Qui Sum | last post by:
I write ip/port scanner so users using search on our LAN know if the particular ftp is online or not. The class I write has the following structure: public class IPScanner { public...
0
by: Jean-Paul Calderone | last post by:
On Sat, 23 Aug 2008 02:25:17 +0800, Leo Jay <python.leojay@gmail.comwrote: No - it's just what I said. create_socket creates one socket and passes it to read_socket and write_socket. ...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.